joon hee - StandardLibrary-1.81

Documentation | Source

NAME

Function - deal with pieces of reusable code.

SYNOPSIS

        var x = function(a,b) {
                this.a = a;
                this.b = b;
        };
        
        x.apply(null, ["a", "b"]);

DESCRIPTION

A function is a piece of reusable code that takes a group of arguments, performs statements, and then returns some value.

METHODS

Inherited

From Object.prototype: hasOwnProperty, isPrototypeOf, propertyIsEnumerable, unwatch, watch

Constructor()

*** Not Implementable In Standard JavaScript

This creates a new function object.

toString() Returns String

*** Not Implementable In Standard JavaScript

This returns a string representation of the function.

apply(Object thisArg, Array argsArray) Returns Any

call(Object thisArg, *@argsArray) Returns Any

toSource() Returns String

Returns a source representation of the function.

AUTHOR

Jhuni, <jhuni_x@yahoo.com>

COPYRIGHT

Public Domain

/*=pod

=head1 NAME

Function - deal with pieces of reusable code.

=head1 SYNOPSIS

	var x = function(a,b) {
		this.a = a;
		this.b = b;
	};
	
	x.apply(null, ["a", "b"]);
	
=head1 DESCRIPTION

A function is a piece of reusable code that takes a group of arguments, performs statements, and then returns some value.

=head1 METHODS

=head2 Inherited

From Object.prototype:
hasOwnProperty, isPrototypeOf, propertyIsEnumerable, unwatch, watch

=cut*/



/*=pod

=head2 Constructor()

*** Not Implementable In Standard JavaScript

This creates a new function object.

=cut*/



/*=pod

=head2 toString() Returns String

*** Not Implementable In Standard JavaScript

This returns a string representation of the function.

=cut*/



/*=pod

=head2 apply(Object thisArg, Array argsArray) Returns Any

=cut*/

Function.prototype.apply = function(o, p) {
	if( p != null && !(p instanceof Array) && typeof p.callee != "function" ) {
		throw new Error("second argument to Function.prototype.apply must be an array");
	}
	
	o = (o == undefined || o == null) ? window : Object(o);

	if( p == null ) {
		p = []
	}

	// Establish parameters:
	var parameters = [];
	for ( var i = 0, l = p.length; i < l; i++ ) {
		parameters[i] = 'p[' + i + ']';
	}
	
	// Estbalish a temporaryName that is undefined
	var temporaryName = '__apply__';
	while( o[temporaryName] != undefined ) {
		temporaryName += "_";
	}

	o[temporaryName] = this;
	var rval = eval('o.' + temporaryName + '(' + parameters.join(', ') + ')' );
	delete o[temporaryName];

	return rval;
};


/*=pod

=head2 call(Object thisArg, *@argsArray) Returns Any

=cut*/

Function.prototype.call = function() {
	
	var thisArg = typeof arguments[0] != 'undefined' ? arguments[0] : {};

	var argsArray = [];
	for( var i = 1, l = arguments.length; i < l; i++ ) {
		argsArray[argsArray.length] = arguments[i];
	}
	
	return this.apply( thisArg, argsArray );

};


/*=pod

=head2 toSource() Returns String

Returns a source representation of the function.

=cut*/

Function.prototype.toSource = function() {
	return( '(' + this.toString() + ')' );
};





/*=pod

=head1 AUTHOR

Jhuni, <jhuni_x@yahoo.com>

=head1 COPYRIGHT

Public Domain

=cut*/