Skip to content

Instantly share code, notes, and snippets.

@nowelium
Created August 18, 2011 11:00
Show Gist options
  • Save nowelium/1153836 to your computer and use it in GitHub Desktop.
Save nowelium/1153836 to your computer and use it in GitHub Desktop.
override method
var Hoge = function (){};
Hoge.prototype.foo = function (){
return 'hello';
};
var a = new Hoge();
a.foo();
# ==> 'hello'
var bar = function (){
return 'world';
};
var foo = a.foo;
a.foo = bar;
a.foo();
# ==> 'world'
foo()
# ==> 'hello'
class Hoge:
def foo(self):
return 'hello'
a = Hoge()
a.foo()
# ==> 'hello'
def bar():
return 'world'
foo = a.foo
a.foo = bar
a.foo()
# ==> 'world'
foo()
# ==> 'hello'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment