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 problem in case of primitive types too like Number. It seems unclear to you what I'm trying to explain about the use of "new" to call the constructor vs assigning the constructor by reference to some var. I am not sure what the confusion is in my case aside from the primitive type case, so would love to learn if there is actually some confusion about the effect of new! I think it's important to understand how JavaScript works if you are programming in any language that compiles to it.
Sent from my iPhone > On Sep 8, 2015, at 5:00 AM, Thomas Heller <[email protected]> wrote: > > 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 (prototype) but not equal to MyClass. > > What is going on with Numbers is related to boxing, so there is a perfectly > fine explanation but that doesn't make it less confusing when you first > encounter it. > > Enough of this, back to topic. Don't extend Native types. ;) > > /thomas > > -- > Note that posts from new members are moderated - please be patient with your > first post. > --- > You received this message because you are subscribed to the Google Groups > "ClojureScript" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/clojurescript. -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/clojurescript.
