<https://lh3.googleusercontent.com/-Ywd-xZFHfoo/Wpuo0d-ZmjI/AAAAAAAACL0/ZEP7Iq_1XTkPtaQWMr1P5bsrG1HPXusBQCLcBGAs/s1600/Screen%2BShot%2B2018-03-04%2Bat%2B1.04.41%2BAM.png>
Granted, bad practice to add prototypes to primitives, but, still, this is 
strange:

Array.prototype.group = function (by) {
    console.log('hello', by)
}

(function() {
    [1,2,3].group
}())

setTimeout(() => {
    [1,2,3].group
    console.log('uhm.')
},4000)

Executed on node.js by copying it into a file named test.js and running 
node test.js produces:

hello undefined

uhm.


Although, executing it in a node repl line produces, just (no hello):

uhm.


Executed in chrome dev tools produces:

<https://lh3.googleusercontent.com/-Ywd-xZFHfoo/Wpuo0d-ZmjI/AAAAAAAACL0/ZEP7Iq_1XTkPtaQWMr1P5bsrG1HPXusBQCLcBGAs/s1600/Screen%2BShot%2B2018-03-04%2Bat%2B1.04.41%2BAM.png>



Then finally, if you try and actually run [1,2,3].group('foo') in Safari, 
Firefox both setTimeout version and anonymous function execution context 
succeeds, in node and V8 Chrome it fails with an undefined error. 


This is wildly and bizarrely inconsistent.  It seems overloading primitives 
has bizarre and inconstant behavior, is their a rational behavior for this?

-- 
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to