Skip to content

Instantly share code, notes, and snippets.

@kitsuyui
Created March 2, 2015 18:29
Show Gist options
  • Save kitsuyui/b0c129ad340fe2282d63 to your computer and use it in GitHub Desktop.
Save kitsuyui/b0c129ad340fe2282d63 to your computer and use it in GitHub Desktop.
「 JS のメソッドの貸し借り (apply 使うやつ ) 」を Python でやるには ref: http://qiita.com/kitsuyui/items/0482de343f88399464b7
class A(object):
def __init__(self):
self.value = 1
class B(object):
def __init__(self):
self.value = 2
def show(self):
print(self.value)
a = A()
B.__dict__['show'](a)
function A () {
this.value = 1;
}
function B () {
this.value = 2;
}
B.prototype.show = function show () {
console.log(this.value);
};
var a = A();
B.prototype.show.apply(a); // まるで「 B のメソッドである show を a が借りて使ってる」よう
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment