为什么在 jQuery 中 core.js
不是 extend
定义如下:
jQuery.extend = jQuery.fn.extend = function() {
...
}
而不是像这样的原型(prototype):
jQuery.prototype.extend = jQuery.fn.prototype.extend = function() {
...
}
据推测,对于前者,从 jQuery 创建的对象将没有扩展功能。
最佳答案
因为 jQuery.fn === jQuery.prototype
它是在原型(prototype)上定义的。 jQuery 刚刚决定将原型(prototype)别名为 .fn
这是为什么
$().extend({
"lulz": "baz"
}, {
"more-lulz": "no wai"
})["more-lulz"] === "no wai"; // true
关于javascript - 为什么在 jQuery 中 core.js 不是用原型(prototype)定义的扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8928533/