这个.e在javascript中是什么
我正在学习创建类似jquery的库,并试图理解一段代码,其中this.e给我带来了困难,这个'e'来自何处,他们正在为它分配对象,但当他们返回这个时,他们只返回这个而不是这个.e这个.e在javascript中是什么,javascript,javascript-objects,Javascript,Javascript Objects,我正在学习创建类似jquery的库,并试图理解一段代码,其中this.e给我带来了困难,这个'e'来自何处,他们正在为它分配对象,但当他们返回这个时,他们只返回这个而不是这个.e function _(a) { var b = { key: "some val" }; if (a) { if (window === this) { return new _(a) } this.e = document.getElementById(a);
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>
点击
当参数为event时,使用e作为函数参数名只是一种惯例。在这里的示例中,事件是onclickthis.e
来自this.e=document.getElementById(a)代码>。如果这还不能回答您的问题,我想您需要提供更多的细节,说明哪些部分让您感到困惑,例如,为什么您对这个.e=X
感到困惑,但对\uuu.prototype=Y
没有困惑?请参阅:如果您对此感到困惑,我不确定写一个像jquery这样的库对你来说是不是一个好主意。因为原型是存在的,这是内置的问题。在eIn OP的例子中,e
似乎是一个元素,而不是一个事件。这毫无意义e
从未用作函数参数,e
不是事件!