Unexpected behavior in Firefox when getter returns a function

Object.defineProperty(Number.prototype, 'foo', { get: function () { var me = this return function () { return me.valueOf() } } }) console.log(5..foo()) 

These are 5 logs in Chrome, but 0 in Firefox.

 Object.defineProperty(Number.prototype, 'bar', { get: function () { return this.valueOf() } }) console.log(5..bar) 

These are 5 logs in both browsers as expected.

Can someone explain this behavior and perhaps suggest how the first example can be rewritten to work in Firefox, like in Chrome?

jsfiddle.net/V2sHg/2/

+4
source share
1 answer

It works for me on FF when using "new Number (value)", but not using directly "number":

Try:

 var n = new Number(8); n.foo(); --> 8 
0
source

All Articles