博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

js 如何实现面向对象

Posted on 2019-06-14 14:52  taigudaren  阅读(329)  评论(0)    收藏  举报
var Person = function(name, email, website){
this.name = name;
this.email = email;
this.website = website;
this.sayHello = function(){
var hello = "Hello, I'm "+ this.name + ", \n" +
"my email is: " + this.email + ", \n" +
"my website is: " + this.website;
alert(hello);
};
};
var chenhao = new Person("Chen Hao", "haoel@hotmail.com",
"http://coolshell.cn");
chenhao.sayHello();