【发布时间】:2017-03-15 04:43:24
【问题描述】:
我正在学习制作像 jquery 这样的库,并试图理解一段代码,this.e 让我很难过,这个 'e' 来自哪里,他们正在为它分配对象,但是当他们返回这个时,他们返回只是这不是this.e。
function _(a) {
var b = {
key: "some val"
};
if (a) {
if (window === this) {
return new _(a)
}
this.e = document.getElementById(a);
return this
} else {
return b
}
}
_.prototype = {
hide: function() {
this.e.style.display = "none";
return this
}
HTML
<button onclick="_('abc')">click</button>
<div id="abc" style="width: 200px; height: 100px; background-color: pink;"> </div>
【问题讨论】:
-
this.e来自this.e = document.getElementById(a);。如果那不能回答您的问题,我认为您需要提供更多详细信息,说明哪些部分让您感到困惑,EG。为什么你对this.e = X感到困惑,却对_.prototype = Y不感到困惑? -
因为原型在那里,那是内置的东西
-
问题是什么是.e
-
你应该研究动态编程语言。您可以在运行时将任何内容分配给对象。
标签: javascript javascript-objects