jQuery 构造函数和初始化
如果我发出问题,
console.dir(jQuery.prototype)
我会得到 jQuery 对象中的方法和属性的漂亮列表。但构造函数和 init 是红色的,旁边有一个小加号。
问:构造函数和 init 与其他函数有何不同?
If I issue
console.dir(jQuery.prototype)
I get a beautiful list of the methods and properties that are in the jQuery object. But constructor and init are in red with a little plus sign next to them.
Q: What makes constructor and init different than the other functions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Firebug 检查函数是否看起来像类函数(obj.prototype 包含至少 1 个属性),并将其显示为具有可扩展属性的类。
http:// /code.google.com/p/fbug/source/browse/branches/firebug1.8/content/firebug/dom/domPanel.js#531
http://code .google.com/p/fbug/source/browse/branches/firebug1.8/content/firebug/dom/domPanel.js#1960
中运行此命令来测试它
您可以通过在 Firebug输出
Firebug checks if a function looks like a Class function (obj.prototype contains atleast 1 property), and shows it as a Class with expandable properties.
http://code.google.com/p/fbug/source/browse/branches/firebug1.8/content/firebug/dom/domPanel.js#531
http://code.google.com/p/fbug/source/browse/branches/firebug1.8/content/firebug/dom/domPanel.js#1960
You can test it out by running this in Firebug
Output
我想这是因为构造函数和 init 不仅仅是“纯”函数。这意味着它们具有附加属性(例如 init 有其自己的原型),这就是它们可扩展的原因。为了进一步说明这一点:
换句话说:函数是一个对象,这意味着您可以附加任何您想要的属性。
I guess it's because constructor and init are not just "pure" functions. This means they have additional properties (e.g. init has its own prototype), and that's why they are expandable. To illustrate this a bit further:
In other words: A function is an Object, this means you can attach any properties you want.
它表明这些函数具有为其定义/设置的附加属性/方法。
It shows that these functions have additional properties/methods defined for / set on them.