【发布时间】:2013-12-20 00:14:45
【问题描述】:
我想创建自己的 DOM 对象类型:
var Obj = function(id) {
this.id = id;
this.constructor.prototype = document.getElementById(id);
};
var x = new Obj("a_div"); //Success
alert(x.type); //Successfully alert "div"
x.innerHTML = "TEST"; //This does not update the actual div html on the page!!!
我希望对这个对象的任何函数调用都会被转发到实际的 DOM 对象。我怎样才能做到这一点?
【问题讨论】:
-
这似乎不像你描述的那样工作(
div没有被提醒):jsfiddle.net/y3Je3/1 -
您是否要扩展 div 对象?我不认为你可以。
-
@RocketHazmat 我想委托它..
-
@texasbruce:我不太确定你能做到。
-
@AndrewWhitaker 当我在 chrome 上测试时它起作用了。将重新测试
标签: javascript oop