cuốn sách gpt4 ai đã làm

javascript - jQuery 构造函数和初始化

In lại Tác giả: Hồ Xil 更新时间:2023-11-01 02:44:12 33 4
mua khóa gpt4 Nike

如果我发布

console.dir(jQuery.prototype)

我得到了 jQuery 对象中的方法和属性的漂亮列表。但是 constructor 和 init 是红色的,旁边有一个小加号。

问:constructor 和 init 与其他函数有何不同?

câu trả lời hay nhất

Firebug 检查函数是否看起来像类函数(obj.prototype 包含至少 1 个属性),并将其显示为具有可扩展属性的类。

http://code.google.com/p/fbug/source/browse/branches/firebug1.8/content/firebug/dom/domPanel.js#531

 if (isClassFunction(val))
this.addMember(object, "userClass", userClasses, name, val, level, 0, context);

http://code.google.com/p/fbug/source/browse/branches/firebug1.8/content/firebug/dom/domPanel.js#1960

function isClassFunction(fn)
{
thử
{
for (var name in fn.prototype)
trả về đúng sự thật;
} catch (exc) {}
trả về sai;
}

你可以在 Firebug 中运行它来测试它

function isClassFunction(fn)
{
thử
{
for (var name in fn.prototype)
trả về đúng sự thật;
} catch (exc) {}
trả về sai;
}
test = [jQuery.prototype.init, jQuery.prototype.constructor, jQuery.prototype.each, jQuery.prototype.get];
for(var i = 0; i < test.length; i++) {
console.log("" + i + ": " + isClassFunction(test[i]));
}

输出

0: true
1: true
2: false
3: false

关于javascript - jQuery 构造函数和初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6447217/

33 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress