Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

안혁준/class.js: Difference between revisions

From ZeroWiki
imported>qa22ahj
No edit summary
imported>qa22ahj
No edit summary
Line 1: Line 1:
----
----
== 소스코드 ==
== 소스코드 ==
  /**
  /**
   * @author Blue Mir
   * @author Blue Mir
   * /
   */
  Function.prototype.extend = function(superclass)
  Function.prototype.extend = function(superclass)
  {
  {
  if(this.prototype.superclass)
if(this.prototype.superclass)
  throw new SyntaxError("이미 superclass를 가지고 있습니다.");
throw new SyntaxError("이미 superclass를 가지고 있습니다.");
  var proto = new superclass();
var proto = new superclass();
  for(var p in proto)
for(var p in proto)
  {
{
  if(proto.hasOwnProperty(p)) delete proto[p];
if(proto.hasOwnProperty(p)) delete proto[p];
  }
}
  proto.constructor = this;
proto.constructor = this;
  proto.superclass = superclass;
proto.superclass = superclass;
  this.prototype = proto;
this.prototype = proto;
  return this;
return this;
  };
  };
  Function.prototype.implement = function()
  Function.prototype.implement = function()
  {
  {
  for(var i = 0; i < arguments.length; i++)
for(var i = 0; i < arguments.length; i++)
  {
{
  var implementClass = arguments[i];
var implementClass = arguments[i];
  for(var p in implementClass.prototype)
for(var p in implementClass.prototype)
  {
{
    var fn = implementClass.prototype[p];
var fn = implementClass.prototype[p];
    if(typeof fn == "function")
if(typeof fn == "function")
    {
{
    this.prototype[p] = fn;
this.prototype[p] = fn;
    }
}
  }
}
  }
}
  return this;
return this;
  };
  };
----
----



Revision as of 15:46, 18 June 2012


소스코드

/**
 * @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;
};