JavaScript加强之Prototype

来源:互联网 发布:雀神作弊软件 编辑:程序博客网 时间:2024/04/30 13:57

Prototype:

*  prototype是function中的一个属性,也是一个对象

*  prototype是一个json格式的对象,可以动态的往json中添加一些内容

*  根据构造器可以创建对象,而创建出来的对象就拥有了prototype中的数据


function Person(){}function Student(){}Person.prototype.name = function(){alert("name");};Person.prototype.age = 55;Person.prototype["sex"] = "man";Person.prototype["person"] = Student;var p = new Person();//alert(p.age);//alert(Person.age);function SuperPerson(){}//将Person的原型赋值给SuperPerson的原型//方法一:SuperPerson.prototype = Person.prototype;//方法二:SuperPerson.prototype = p;alert(new SuperPerson().age);alert(new SuperPerson()['sex']);//man




原创粉丝点击