phoboslab / Ejecta

A Fast, Open Source JavaScript, Canvas & Audio Implementation for iOS
2.81k stars 321 forks source link

the feature for "instanceof" checking #652

Open finscn opened 8 years ago

finscn commented 8 years ago

Hi , @phoboslab ,

In Ejecjta , the below "instanceof" checking can't pass :

img instanceof HTMLImageElement 
canvas instanceof HTMLCanvasElement
video instanceof HTMLVideoElement
audio instanceof HTMLAudioElement

In PIXI.js v4 , the "instanceof" checking is very useful , I hope Ejecta could support it.

~~I add this feature in my fork version ~~ https://github.com/finscn/Ejecta/commit/5f80a03747233efba914a2793bf4db10c9159d80

I hope it could help you.

There are too many differences between my fork version and origin ejecta , So I don't give a PR. And I found that you have never accept my PR , maybe there are too many differences between our code spec. & style , So I think my PR is useless for you.

finscn commented 8 years ago

I found an easy way to implement this feature , just add this code to Ejecta.js

(function(){

    var element = document.createElement("img");
    HTMLImageElement = function(){};
    HTMLImageElement.prototype = element.__proto__;

    var element = document.createElement("canvas");
    HTMLCanvasElement = function(){};
    HTMLCanvasElement.prototype = element.__proto__;

    var element = document.createElement("video");
    HTMLVideoElement = function(){};
    HTMLVideoElement.prototype = element.__proto__;

    var element = document.createElement("audio");
    HTMLAudioElement = function(){};
    HTMLAudioElement.prototype = element.__proto__;

})();

Notice : the code must be after "window.document = { ... }" in Ejecta.js.