一、JavaScript对象的创建
(1)对象方法
function Student(name){ this.name=name; this.showName=function(){ alert("my name is "+this.name); }; }
调用showName方法:
new Student(‘a‘).showName();
对象方法的调用,类要生成一个实例,该实例可以调用该方法;
(2)类方法
Student.showAge=function(){ alert(‘age is 20‘); }
调用方式:
Student.showAge();
类方法相当于C#的静态方法,不需要new一个对象实例,可以直接调用;
(3)继承方法
Student.prototype.sayHello=function Hello(){ alert(‘hello‘); }
调用方法:
new Student(‘a‘).sayHello();
原型方法一般用与继承父类的方法和方法共享;
二、
参考链接
1、http://www.cnblogs.com/yjf512/archive/2011/06/03/2071914.html
2、http://bbs.csdn.net/topics/390775296
原文:http://www.cnblogs.com/zqllove/p/5237971.html