Object.defineProperty(Number.prototype, 'foo', {
get: function () { return this }
})
console.log(10.5.foo)
console.log(10..foo) // 0 in IE9!
console.log(10.0.foo) // 0 in IE9!
console.log(10.01.foo)
console.log((10).foo) // 0 in IE9!
var x = 10
console.log(x.foo) // 0 in IE9!
Can anyone explain this behaviour and/or suggest a workaround?
jsfiddle.net/yr7hQ/
I can't explain that result, but you also asked for a workaround.
Demo: http://jsfiddle.net/ThinkingStiff/FJ7Qx/
Script:
Number.prototype.foo = function() { return Number( this ) };
console.log(10.5.foo())
console.log(10..foo())
console.log(10.0.foo())
console.log(10.01.foo())
console.log((10).foo())
var x = 10
console.log(x.foo())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With