// -- @Author: Dongzhejia
// -- @Date: 2018年04月16日
// -- @des:js 类的简易实现
function jsClass (parent) {
if (parent&&typeof(parent)!="function") {
throw new Error("parent tyoe error need function!!!")
return nil
};
var _class = function () {
if(this.ctor){
this.ctor.apply(this, arguments)
}
}
if(parent){
_class.prototype.__proto__ = parent.prototype
_class.super = parent.prototype
}
return _class
}
//以下为使用例子
//基类
var mjbase = jsClass()
//构造方法
mjbase.prototype.name = "麻将基类"
mjbase.prototype.ctor = function(arg) {
console.log("我是麻将基类方法,实例对象为:"+this.name)
};
//子类
var mj_tuidaohu = jsClass(mjbase)
mj_tuidaohu.prototype.name = "推到胡"
mj_tuidaohu.prototype.ctor = function(arg) {
//调用父类方法
mj_tuidaohu.super.ctor.call(this)
console.log("我是推到胡方法,实例对象为:"+this.name)
};
var mj = new mj_tuidaohu()
module.exports = jsClass
// -- @Date: 2018年04月16日
// -- @des:js 类的简易实现
function jsClass (parent) {
if (parent&&typeof(parent)!="function") {
throw new Error("parent tyoe error need function!!!")
return nil
};
var _class = function () {
if(this.ctor){
this.ctor.apply(this, arguments)
}
}
if(parent){
_class.prototype.__proto__ = parent.prototype
_class.super = parent.prototype
}
return _class
}
//以下为使用例子
//基类
var mjbase = jsClass()
//构造方法
mjbase.prototype.name = "麻将基类"
mjbase.prototype.ctor = function(arg) {
console.log("我是麻将基类方法,实例对象为:"+this.name)
};
//子类
var mj_tuidaohu = jsClass(mjbase)
mj_tuidaohu.prototype.name = "推到胡"
mj_tuidaohu.prototype.ctor = function(arg) {
//调用父类方法
mj_tuidaohu.super.ctor.call(this)
console.log("我是推到胡方法,实例对象为:"+this.name)
};
var mj = new mj_tuidaohu()
module.exports = jsClass