JavaScript面向对象编程

构造函数的使用

//创建一个Student原型

'function Student (name){
this.name =name;
this.say=function(){
return "Hello, "+this.name+"!"
}
}'

//使用Student原型创建一个小明实例
'
var xiaoming =new Student('小明');
xiaoming.name //‘小明’
xiaoming.say() //"Hello, 小明!"
'
//使用prototype属性创立实例共同方法
Student.prototype.run = function(){
return this.name+'running!'
}

xiaohong.run =xiaoming.run; //ture;

posted @ 2022-04-01 15:51  Chiffon1996  阅读(26)  评论(0)    收藏  举报