开发者

JavaScript Object.prototype by value

I want to do something like Object.prototype.dataTransfer = new DataTransfer();, but I want every new object to have it's own dataTransfer. How do I do this?

For example, if I do

var a = new Object();
var b = new Object();
Object.prototype.dataTransfer = new Object();
a.开发者_运维知识库dataTransfer.prop = 1;
b.dataTransfer.prop = 2;

I want a.dataTransfer.prop to still be 1, not 2.

For context, I'm trying to hack WebKit and IE so that the .dataTransfer object of the drag and drop events works appropriately.


Normally you'd add it in the constructor, but since you're wanting to extend a host object (HTMLDomElement), what you want isn't really possible. However, if you broaden the definition of your problem beyond specific implementation details like this, there may be another way, such as a library with a different (possible) user facing API that works differently depending on which browser it is in, successfully abstracting the browser and supplying a uniform API.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜