面向对象的js探索2

修改demo.js代码
[code]
/**
* …
* @author amyflash.com
*/

(function() {

function Person(name,address){
this.name=name;
this.address = address;
}

Person.prototype.sayHello = function()
{
console.log(this.name+” says hello”);
};

Person.BUDONG=”I’m static var”;
var lee = new Person(“amyflash”,”shanghai”);
lee.sayHello();
})();
[/code]
知识点解释:
1.Person类是一个dynamic类型的类,可以在外面用.prototype.function的形式动态添加成员方法和变量,注意sayHello函数里的name前面加了个this.
2. Person.BUDONG=”I’m static var”;申明并赋值了一个Person类的静态变量

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>