Comparing version 0.0.3 to 0.0.4
162
index.js
@@ -1,86 +0,98 @@ | ||
var slice = [].slice; | ||
(function() { | ||
function createInstance(Fn, args) { | ||
var args_str = slice.call(args).map(function(arg, i) { | ||
return 'args[' + i + ']'; | ||
}); | ||
var instance = eval('new Fn(' + args_str.join(',') + ')'); | ||
return instance; | ||
}; | ||
function createInstance(Fn, args) { | ||
var args_str = [].slice.call(args).map(function(arg, i) { | ||
return 'args[' + i + ']'; | ||
}); | ||
var instance = eval('new Fn(' + args_str.join(',') + ')'); | ||
return instance; | ||
}; | ||
function getPropertyNames(obj) { | ||
var nameList = Object.getOwnPropertyNames(obj); | ||
if (obj.__proto__) { | ||
nameList.push.apply(nameList, getPropertyNames(obj.__proto__)); | ||
} | ||
return nameList; | ||
}; | ||
function createSuper(_self, proto) { | ||
var _super = function() { | ||
if (proto.constructor) { | ||
return createInstance(proto.constructor, arguments); | ||
function getPropertyNames(obj) { | ||
var nameList = Object.getOwnPropertyNames(obj); | ||
if (obj.__proto__) { | ||
nameList.push.apply(nameList, getPropertyNames(obj.__proto__)); | ||
} | ||
return proto; | ||
return nameList; | ||
}; | ||
delete _super.name; | ||
var nameList = getPropertyNames(proto); | ||
var nameLength = nameList.length; | ||
for (var i = 0; i < nameLength; i++) { | ||
var name = nameList[i]; | ||
if (name == "_super" || | ||
name == "_extends" || | ||
name == "_static" || | ||
name == "constructor") { | ||
continue; | ||
} | ||
if (typeof proto[name] === 'function') { | ||
_super[name] = _super[name] || proto[name].bind(_self); | ||
function createSuper(_self, proto) { | ||
var _super = function() { | ||
if (proto.constructor) { | ||
return createInstance(proto.constructor, arguments); | ||
} | ||
return proto; | ||
}; | ||
delete _super.name; | ||
var nameList = getPropertyNames(proto); | ||
nameList.forEach(function(name) { | ||
if (name == "_super" || | ||
name == "_extends" || | ||
name == "_static" || | ||
name == "constructor") { | ||
return; | ||
} | ||
if (typeof proto[name] === 'function') { | ||
_super[name] = _super[name] || proto[name].bind(_self); | ||
} else { | ||
_super[name] = _super[name] || proto[name]; | ||
} | ||
}); | ||
_super.__proto__ = {}; | ||
return _super; | ||
}; | ||
function defineClass(def) { | ||
var classProto = ((typeof def === 'function') ? def() : def) || {}; | ||
var constructor = classProto.constructor; | ||
var classExtends = classProto._extends; | ||
var clsssStatic = classProto._static || {}; | ||
if (typeof classExtends === 'function') { | ||
classProto.__proto__ = classExtends.prototype; | ||
clsssStatic.__proto__ = classExtends; | ||
} else if (classExtends) { | ||
classProto.__proto__ = classExtends; | ||
} else { | ||
_super[name] = _super[name] || proto[name]; | ||
classProto.__proto__ = {}; | ||
} | ||
classProto.__defineGetter__('_super', function() { | ||
this.__super__ = this.__super__ || createSuper(this, classProto.__proto__); | ||
return this.__super__; | ||
}); | ||
Class.prototype = classProto; | ||
Class.__proto__ = clsssStatic; | ||
function Class() { | ||
var instance = this; | ||
if (constructor != null && | ||
constructor != Object) { | ||
instance = constructor.apply(instance, arguments) || instance; | ||
} else if (typeof classExtends === 'function') { | ||
instance = createInstance(classExtends, arguments) || instance; | ||
} | ||
instance.constructor = Class; | ||
instance.__proto__ = Class.prototype; | ||
instance._extends = null; | ||
instance._static = Class; | ||
return instance; | ||
} | ||
return Class; | ||
}; | ||
defineClass.prototype.__proto__ = Function.prototype; | ||
defineClass.Class = defineClass; | ||
if (typeof module != 'undefined') { | ||
module.exports = defineClass; | ||
} | ||
_super.__proto__ = {}; | ||
return _super; | ||
}; | ||
function defineClass(def) { | ||
var classProto = ((typeof def === 'function') ? def() : def) || {}; | ||
var constructor = classProto.constructor; | ||
var classExtends = classProto._extends; | ||
var clsssStatic = classProto._static || {}; | ||
if (typeof classExtends === 'function') { | ||
classProto.__proto__ = classExtends.prototype; | ||
clsssStatic.__proto__ = classExtends; | ||
} else if (classExtends) { | ||
classProto.__proto__ = classExtends; | ||
} else { | ||
classProto.__proto__ = {}; | ||
if (typeof define == 'function' && define.amd) { | ||
define('cify', [], function() { | ||
return defineClass; | ||
}); | ||
} | ||
classProto.__defineGetter__('_super', function() { | ||
this.__super__ = this.__super__ || createSuper(this, classProto.__proto__); | ||
return this.__super__; | ||
}); | ||
Class.prototype = classProto; | ||
Class.__proto__ = clsssStatic; | ||
function Class() { | ||
var instance = this; | ||
if (constructor != null && | ||
constructor != Object) { | ||
instance = constructor.apply(instance, arguments) || instance; | ||
} else if (typeof classExtends === 'function') { | ||
instance = createInstance(classExtends, arguments) || instance; | ||
} | ||
instance.constructor = Class; | ||
instance.__proto__ = Class.prototype; | ||
instance._extends = null; | ||
instance._static = Class; | ||
return instance; | ||
if (typeof window != 'undefined') { | ||
window.cify = window.Class = defineClass; | ||
} | ||
return Class; | ||
}; | ||
defineClass.prototype.__proto__ = Function.prototype; | ||
defineClass.Class = defineClass; | ||
module.exports = defineClass; | ||
})(); |
{ | ||
"name": "cify", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "一个面向对象辅助模块", | ||
@@ -11,3 +11,4 @@ "main": "index.js", | ||
"class", | ||
"classjs" | ||
"classjs", | ||
"cify" | ||
], | ||
@@ -14,0 +15,0 @@ "author": "Houfeng", |
4987
6
145