:) Indeed ... different than the usual way, see below for how "new" changes
'this' from being the object whatAmI is defined on to

var T = function() { console.log('constructor called')}

T.prototype = {}

T.prototype.whatAmI = function() {
return {type: Object.prototype.toString.call(this), isEqualToPrototype:
(this === T.prototype)}
}

var x = new T  // (x is instance of T) prints constructor called

x instanceof T

true

x.whatAmI()
//prints: {type: "[object Object]", isEqualToPrototype: false}

var y = T  (y is T)

y instanceof T

false

y.prototype.whatAmI()

Object {type: "[object Object]", isEqualToPrototype: true}

See?

WTF indeed, in case of primitive types.

Maybe Brendan Eich can explain the primitive types stuff to me but last
time I mentioned ClojureScript on webapps mailing list he unleashed a huge
rant about how I should not speak of that which I don't understand. He was
clearly triggered by mention of CLJS. Seems like it has gotten under his
skin, especially with guys like Peter Hunt admitting that the React team
has been borrowing idea from CLJS. Microsoft lead on IE was far more
generous and open to discussing ideas around a thread safe version of the
DOM...



On Mon, Sep 7, 2015 at 2:55 PM, Thomas Heller <th.hel...@gmail.com> wrote:

>
>
> > The point I wanted to make is 'this' without 'new' will refer to the
> object the function is defined on be it 'window' or whatever object.
> >
>
> That is incorrect. "this" is the actual number, not window. new or not.
> Behavior is probably different for other types. ;)
>
> Number.prototype.addFive = function() { return this + 5 };
> var x = 1;
> x.addFive(); => 6
> var x = new Number(3)
> x.addFive(); => 8
>
> Anyways, we agree that JS is full of WTF. Let's enjoy our sweet sweet CLJS
> world. :)
>
> Cheers,
> /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 clojurescript+unsubscr...@googlegroups.com.
> To post to this group, send email to clojurescript@googlegroups.com.
> 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 clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to