Hmm I think you have those confused.
Take the equivalent from Java:
class MyClass {
}
MyClass x = new MyClass();
Class y = MyClass.class;
or JS:
var MyClass = function() { /* ctor */ };
var inst = new MyClass()
inst != MyClass
inst.prototype == MyClass
inst is an instance of MyClass (prototy
Crossed context here.
What I was pointing to is that trying to create an instance without "new" means
that 'this' in the prototype method whatAmI will point to the prototype itself
rather than the instance. That is what the === proves in the example in my
previous rely. I thought it was the pr
Continuing about the effect of "new" in JS since it is a subject of
exploration/learning at this point, and I believe firmly in knowing your JS
in order to master your CLJS, so maybe one day you could fix a bug in CLJS
itself and be a contributor, which is hard to do in most cases if you don't
know
<<
var MyClass = function() { /* ctor */ };
var inst = new MyClass()
inst.prototype == MyClass
>>
"inst is an instance of MyClass (prototype) but not equal to MyClass."
Yes, no one argues with that. It is an instance of MyClass and it is
obviously !== MyClass,
But saying 'inst.prototype == MyC
>
> var x = T
> x.prototype.whatAmI()
> prints: {type: "[object Object]", isEqualToPrototype: true} < because
> 'this' in whatAmI now points to T.prototype
>
The thing is that you are not supposed to call methods on the prototype
directly.
Your code has this in it:
Object.prototype.toS
<<
Your code has this in it:
Object.prototype.toString.call(this)
which is something you usually do not do. The first argument to the .call
function becomes "this" in the context of the function which is "cheating"
and bypassing prototype inheritance. I consider .call equal to reflection
in Java.
Is it always necessary to rewrite a Clojure library in Clojurescript, in order
to use its functions?
There are several third-party Clojure libraries that I'd like to use in a web
page, but cannot find a way to call the Jar methods directly.
--
Note that posts from new members are moderated -
This is a good question.
Until very recently, there was no easy way to share code between
Clojure and ClojureScript at all, although the pure clojure-core stuff
did work pretty much out of the box.
Still it's quite common that a library has dependencies to other
jvm-stuff, or uses jvm-stuff under
Need a Clojurescript REPL? Too lazy to open planck? Use a PDF instead. NB:
Only works in Foxit Viewer (Windows) or Chrome. Adobe and Preview blow the
stack.
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because yo