title | slug | l10n | ||
---|---|---|---|---|
方法 |
Glossary/Method |
|
{{GlossarySidebar}}
方法是一种作为{{glossary("object","对象")}}的{{glossary("property","属性")}}的{{glossary("function","函数")}}。方法有两种类型:实例方法是由对象实例执行的内置任务,而静态方法是直接在对象构造函数上调用的任务。
Note
在 JavaScript 中,函数本身也是对象,因此,在这个上下文中,方法实际上是对函数的{{glossary("object reference","对象引用")}}。
当说 F
是 O
的一个方法时,通常意味着 F
将 O
作为其 this
绑定。没有根据它们的 this
值具有不同行为的函数属性(或者根本没有动态 this
绑定的函数——比如绑定函数和箭头函数)可能不被普遍认为是方法。
-
维基百科上的方法
-
在 JavaScript 中定义方法(传统语法与新的简写语法的比较)
-
- {{Glossary("function", "函数")}}
- {{Glossary("object", "对象")}}
- {{Glossary("property", "属性")}}
- {{Glossary("static method", "静态方法")}}