More actions
imported>qa22ahj No edit summary |
(Repair batch-0006 pages from live compare) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 2: | Line 2: | ||
Javascript에서 클래스를 묘사하기 위한 방안. | Javascript에서 클래스를 묘사하기 위한 방안. | ||
마음대로 가져가면 가만 안둠. | ~~마음대로 가져가면 가만 안둠.~~ MIT라이선스 입니다. | ||
---- | ---- | ||
== 소스코드 == | == 소스코드 == | ||
| Line 19: | Line 19: | ||
for(var p in proto) | for(var p in proto) | ||
{ | { | ||
if(proto.hasOwnProperty(p)) delete proto | if(proto.hasOwnProperty(p)) delete proto[p]; | ||
} | } | ||
| Line 33: | Line 33: | ||
for(var i = 0; i < arguments.length; i++) | for(var i = 0; i < arguments.length; i++) | ||
{ | { | ||
var implementClass = arguments | var implementClass = arguments[i]; | ||
for(var p in implementClass.prototype) | for(var p in implementClass.prototype) | ||
{ | { | ||
var fn = implementClass.prototype | var fn = implementClass.prototype[p]; | ||
if(typeof fn == "function") | if(typeof fn == "function") | ||
{ | { | ||
this.prototype | this.prototype[p] = fn; | ||
} | } | ||
} | } | ||
| Line 47: | Line 47: | ||
}; | }; | ||
---- | ---- | ||
Latest revision as of 01:08, 27 March 2026
개요
Javascript에서 클래스를 묘사하기 위한 방안.
~~마음대로 가져가면 가만 안둠.~~ MIT라이선스 입니다.
소스코드
/**
* @author Blue Mir
* @email qa22ahj@naver.com
*/
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;
};