给已有的函数对象增加属性或者方法
导读:给已有的函数对象增加属性或者方法 格式:构造函数名.prototype.新属性或者新方法 菜鸟教程(runoob.com function Students(name, height, age {...
给已有的函数对象增加属性或者方法
格式:构造函数名.prototype.新属性或者新方法
菜鸟教程(runoob.com)
function Students(name, height, age) {
this.name = name;
this.height = height;
this.age = age;
this.outputInfo = function() {
document.write('name = ' + this.name + '' + 'height = ' + this.height + '');
}
}
//增加一个新方法
Students.prototype.newFunction = function() {
document.write('此方法是通过prototype继承后实现的');
}
var stu1 = new Students('zhang', 123, 12);
stu1.outputInfo();
stu1.newFunction();
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 给已有的函数对象增加属性或者方法
本文地址: https://pptw.com/jishu/655717.html
