类似于一个构造化的类,使用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>

相关文章:

  • 2022-01-29
  • 2022-12-23
  • 2021-10-16
  • 2021-08-17
  • 2022-12-23
  • 2021-05-14
猜你喜欢
  • 2022-03-09
  • 2022-12-23
  • 2022-01-06
  • 2021-12-30
  • 2021-07-13
  • 2022-12-23
  • 2021-06-21
相关资源
相似解决方案