迹忆客 专注技术分享

当前位置:主页 > 学无止境 > WEB前端 > JavaScript >

JavaScript foo.prototype.bar 符号

作者:迹忆客 最近更新:2023/01/10 浏览次数:

作为记录一些流行的 HTML 元素 + 属性符号的帖子的后续,这里有一个关于 JavaScript 的类似帖子。

当写(在文本中,而不是在 JavaScript 中)关于特定原型的属性时,我们可以使用 JavaScript 符号 foo.prototype.bar。 但是,通常使用这种更短的(非 JavaScript)表示法:foo#bar。 基本上,哈希 (#) 代表 .prototype。 - 花哨吧?

让我们看一个例子:

var numbers = [1, 2, 3]; // array literal
numbers.push(42); // `numbers` is now `[1, 2, 3, 42]`

这里调用了 Array.prototype.push 方法。 你也可以说 Array#push 被调用了。


关于 jQuery 的注释

为方便起见,jQuery 将 jQuery.prototype 别名为 jQuery.fn。 不要让这个愚弄你! 每当我们使用例如 jQuery(elem).remove() 你仍然在调用 jQuery.prototype.removejQuery.fn.remove 是对它的引用),或者——使用缩写符号——jQuery#remove

还要注意例如之间的区别。 jQuery#mapjQuery.map

jQuery(elems).map(fn); // jQuery#map, which is jQuery.prototype.map (or jQuery.fn.map)
jQuery.map(arr, fn); // jQuery.map

同样,当使用扩展 jQuery.fn 的 jQuery 插件时,我们实际上是在扩展 jQuery.prototype。 在谈论 jQuery 插件时,我一直在使用缩写符号,例如 jQuery#placeholder


IDL 属性

在规范世界中,有时 Foo#bar 表示法用于指代 Foo 的 bar IDL 属性,而不是 foo.prototype.bar

转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处

本文地址:

相关文章

Do you understand JavaScript closures?

发布时间:2025/02/21 浏览次数:108 分类:JavaScript

The function of a closure can be inferred from its name, suggesting that it is related to the concept of scope. A closure itself is a core concept in JavaScript, and being a core concept, it is naturally also a difficult one.

Do you know about the hidden traps in variables in JavaScript?

发布时间:2025/02/21 浏览次数:178 分类:JavaScript

Whether you're just starting to learn JavaScript or have been using it for a long time, I believe you'll encounter some traps related to JavaScript variable scope. The goal is to identify these traps before you fall into them, in order to av

How much do you know about the Prototype Chain?

发布时间:2025/02/21 浏览次数:150 分类:JavaScript

The prototype chain can be considered one of the core features of JavaScript, and certainly one of its more challenging aspects. If you've learned other object-oriented programming languages, you may find it somewhat confusing when you start

JavaScript POST

发布时间:2024/03/23 浏览次数:96 分类:JavaScript

本教程讲解如何在不使用 JavaScript 表单的情况下发送 POST 数据。

扫一扫阅读全部技术教程

社交账号
  • https://www.github.com/onmpw
  • qq:1244347461

最新推荐

教程更新

热门标签

扫码一下
查看教程更方便