js属性prototype的使用

类似于一个构造化的类,使用prototype属性定义方法

<script>
function Person(name) {
this.name = name;
alert(this.name);
}
// 定义Person的原型方法
//Person.method("getName", function() {
Person.prototype.MethodB = function() {
alert( this.name);
// return this.name;
};

// 实例化子类
var nc = new Person("ZhangSan");
nc.MethodB();
</script>

原文地址:https://www.cnblogs.com/chinaagan/p/3183315.html