ES5中的自訂物件類型-prototype
物件的member成員若是function, 通常叫做method.
非static method: 1.
Person.prototype.sayHello = function()
2. in constructor: function Person (){
this.someData = 0;
this.testFun = function{
//can use this.someData to access
}
}
static method:
MyClass.method1 = function ()
. It has no relationship with an object instance of that constructor function http://ithelp.ithome.com.tw/question/10128721static property 也可以透過一樣方式定義:
MyClass.staticProperty1 = "test"
jQuery的library應該主要部份是純function, 部份是static method. e.g.
$('.jQueryButton')
跟 $.get()
Last modified 4yr ago