simulate what native object is not exist
- by Naitro
Here is the situation: I have checking on existing class like:
('Promise' in window) // true/false`
And I wanna force return false or true on it, can I do it?
Yes, I can check it by some other way, like `
window.Promise = undefined;
window.Promise === undefined;
Or something like this, but can I somehow delete this object or simulate something for 'in' operator?
I check specification and v8 code, there is 'in' operator just call 'HasProperty' operator, which realization on c++.. I know 'hack' with faking toString/valueOf methods:
obj = {
toString: function(){ return 'myName'; }
},
obj2 = {};
obj2[obj] = 1; // Object {myName: 1}
May be I can use it in some way? But, as I send string 'Promise' I can't just fake it like this way.. may be exist some way to fake 'HasProperty'?