More actions
imported>qa22ahj No edit summary |
imported>qa22ahj No edit summary |
||
| Line 1: | Line 1: | ||
<code> | |||
/** | |||
* @author Blue Mir | |||
*/ | |||
Function.prototype.extend = function(superclass) | |||
{ | |||
if(this.prototype.superclass) | |||
throw new SyntaxError("이미 superclass를 가지고 있습니다."); | |||
var proto = new superclass(); | |||
for(var p in proto) | |||
{ | |||
if(proto.hasOwnProperty(p)) delete proto[p]; | |||
} | |||
proto.constructor = this; | |||
proto.superclass = superclass; | |||
this.prototype = proto; | |||
return this; | |||
}; | |||
Function.prototype.implement = function() | |||
{ | |||
for(var i = 0; i < arguments.length; i++) | |||
{ | |||
var implementClass = arguments[i]; | |||
for(var p in implementClass.prototype) | |||
{ | |||
var fn = implementClass.prototype[p]; | |||
if(typeof fn == "function") | |||
{ | |||
this.prototype[p] = fn; | |||
} | |||
} | |||
} | |||
return this; | |||
}; | |||
</code> | |||
Revision as of 15:39, 18 June 2012
<code> /**
- @author Blue Mir
*/
Function.prototype.extend = function(superclass) {
if(this.prototype.superclass) throw new SyntaxError("이미 superclass를 가지고 있습니다.");
var proto = new superclass();
for(var p in proto) { if(proto.hasOwnProperty(p)) delete proto[p]; }
proto.constructor = this; proto.superclass = superclass;
this.prototype = proto;
return this; }; Function.prototype.implement = function() { for(var i = 0; i < arguments.length; i++) { var implementClass = arguments[i];
for(var p in implementClass.prototype) { var fn = implementClass.prototype[p]; if(typeof fn == "function") { this.prototype[p] = fn; } } } return this; }; </code>