js中的面向对象

提到js中的面向对象,很多小白就头大,今天我简单的说,你简单的学,轻松~

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

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

"Person"——大写,作为类。

使用prototype来添加公共属性或者方法。

posted @ 2018-11-03 23:17  嘉儿2017  阅读(72)  评论(0编辑  收藏  举报