1. 程式人生 > >js中的面向對象

js中的面向對象

大寫 func this 方法 col style 面向對象 his clas

提到js中的面向對象,很多同學就頭大,今天我簡單的說,你簡單的學,輕松~

function Person(name){
   this.name = name;  
}
Person.prototype.say = function(){
   console.log("我的名字是"+this.name);  
}

var finao = new Person("finao");
finao.say();

"Person"——大寫,作為類。

使用prototype來添加公共屬性或者方法。

js中的面向對象