As much as I distrust goog.typeOf, this isn't its fault. It's really
quite bizarre: AFAICT, typeof (i.e. the JavaScript operator, not the
goog.typeOf function) returns "object" for any value named by `this`:
typeof 5
"number"
Number.prototype.foo = function () { return typeof this; };
[object Function]
(5).foo()
"object"
This is a whole new level of JavaScript wat for me. I've asked the SO
hordes for insight:
http://stackoverflow.com/questions/20636028/typeof-returns-object-for-this-number-elsewhere
Meanwhile, I've discovered that extending the protocol to both `number`
and `js/Number` does work under both execution contexts, a much more
palatable workaround. That's allowed me to move forward with my
current work.
Thanks,
- Chas
On Tue 17 Dec 2013 04:37:56 AM EST, Thomas Heller wrote:
FWIW I had some troubles with native types before, mine were related to IE
though. The culprit for your troubles is goog.typeOf (which is a basic wrapper
arrount js/typeof).
If you run this via phantomjs
-----
console.log("typeof", typeof(5));
Number.prototype.foo = function() {
console.log("typeof prototype", typeof(this));
};
(5).foo();
phantom.exit(0);
-----
You get
typeof number
typeof prototype object
Pretty sure the problem goes away cause in advanced compilation cause it gets
inlined and (.foo 5) is turned into (m 5) skipping the step with this. Just a
guess though.
HTH,
/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.