1. 首页
  2. 考试认证
  3. 其它
  4. inherit js 简单继承模块

inherit js 简单继承模块

上传者: 2024-10-21 00:28:58上传 ZIP文件 3.63KB 热度 1次

继承js简单继承模块用法

function Parent() {}

Parent.prototype.parentMethod = function () { console.log('parent method!'); };

function Child() { Parent.prototype.constructor.call(this); }

设置继承关系在添加子类原型方法前

inherit(Parent, Child);

Child.prototype.childMethod = function () { console.log('child method!'); };

创建子类实例:

var child = new Child();

child.childMethod();

下载地址
用户评论