learning-javascript
  • Introduction
  • JavaScript ES5 教學
    • 工具準備
    • 流程控制
    • JavaScript 基本特性, 變數
    • Function及Callback function
    • Array及JSON的操作
    • Object, Scope, this
    • ES5中的自訂物件類型-prototype
    • 進階-再講prototype
    • JavaScript重點整理
    • Closure
    • 多個JS檔, module, timer
    • 進階-module pattern
    • 其他
  • 實際應用
    • Server - HTTP request & response
    • Client - 用Fetch跟Server要資料
  • JavaScript ES6 教學
    • 箭頭函數Arrow Function
Powered by GitBook
On this page
  • 非自建物件類型的, 即var obj ={};, 可參考上一個章節的Object Literal Notation
  • ES5, 自建物件類型的method宣告方式 以及static method/data:
  1. JavaScript ES5 教學

ES5中的自訂物件類型-prototype

PreviousObject, Scope, thisNext進階-再講prototype

Last updated 7 years ago

非自建物件類型的, 即var obj ={};, 可參考上一個章節的Object Literal Notation

ES5, 自建物件類型的method宣告方式 以及static method/data:

物件的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

static property 也可以透過一樣方式定義:MyClass.staticProperty1 = "test"

jQuery的library應該主要部份是純function, 部份是static method. e.g. $('.jQueryButton') 跟 $.get()

http://ithelp.ithome.com.tw/question/10128721