simulate what native object is not exist

Posted by Naitro on Stack Overflow See other posts from Stack Overflow or by Naitro
Published on 2014-05-29T09:21:31Z Indexed on 2014/05/29 9:24 UTC
Read the original article Hit count: 132

Filed under:
|
|

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'?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about v8