如何覆盖 javascript 的 cloneNode? [英] How do I override javascript's cloneNode?

查看:31
本文介绍了如何覆盖 javascript 的 cloneNode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我目前所拥有的:http://jsfiddle.net/beCVL/5/

这就是我试图覆盖默认 cloneNode 的方式:Object.defineProperty(Object.prototype, "cloneNode", {得到:cloneNode2,设置:cloneNode2});

This is how I'm trying to override the default cloneNode: Object.defineProperty(Object.prototype, "cloneNode", { get: cloneNode2, set: cloneNode2 });

但它不起作用,所以,我认为 Object.prototype 没有 cloneNode,但 Element.prototype 也没有.

but it's not working, so, I think Object.prototype doesn't have cloneNode, but Element.prototype doesn't either.

那么,假设我的方法是正确的,我需要使用哪个类来覆盖 cloneNode?

So, which class do I need to use to override cloneNode, assuming my method is correct?

推荐答案

这一系列的工作正在进行中,但它重新实现了 cloneNode 的功能.http://jsfiddle.net/beCVL/19/

This series of fiddles is a work in progress, but it reimplements cloneNode's functionality. http://jsfiddle.net/beCVL/19/

截至美国东部时间 4 月 4 日上午 10:53,它需要与 IE 一起使用,因为 IE 没有 Node 对象.

as of April 4th, 10:53am EST, it needs to work with IE, as IE doesn't have a Node object.

注意,在 IE 中,原型函数不能被覆盖.因此,cloneNode 的所有实例都必须替换为一个确定要使用哪个版本的 cloneNode 的函数.

Note, that in IE, prototype functions can't be overridden. So, all instances of cloneNode have to be replaced by a function that determines which version of cloneNode to use.

这篇关于如何覆盖 javascript 的 cloneNode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆