Overload function method in javascript

function Foo(){}
Foo.prototype.load=function()
{
alert(“ok”);
}

addMethod(Foo.prototype, “load”, function(name){
alert(name);
});

// addMethod – By John Resig (MIT Licensed)
function addMethod(object, name, fn){
var old = object[ name ];
if ( old )
object[ name ] = function(){
if ( fn.length == arguments.length )
return fn.apply( this, arguments );
else if ( typeof old == ‘function’ )
return old.apply( this, arguments );
};
else
object[ name ] = fn;
}

Advertisements
By huynhvothinh Posted in Uncategorized Tagged

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s