i want to bind a member function
i hope this example will explain what i want to do
(it seems my solution works - but is there a better way?)
// first a simple function variable example
function foo(){
print("foo");
}
// prints foo and foo
function simpleTest(){
foo();
var x=foo;
x();
}
simpleTest();
// now i want to bind a member function to a function variable
// this will not work:
// x=foo.bar; (since "this" will be wrong)
function Foo(bar){
this.b=bar;
}
Foo.prototype.b ar=function()
{
print (this.b);
}
function test() {
var foo=new Foo("bar");
foo.bar(); // print bar
// bind method - is there a simpler way ????
var x=function(y){v ar z=y;return function(){z.ba r();}}(foo);
x(); // print bar
}
test();
i hope this example will explain what i want to do
(it seems my solution works - but is there a better way?)
// first a simple function variable example
function foo(){
print("foo");
}
// prints foo and foo
function simpleTest(){
foo();
var x=foo;
x();
}
simpleTest();
// now i want to bind a member function to a function variable
// this will not work:
// x=foo.bar; (since "this" will be wrong)
function Foo(bar){
this.b=bar;
}
Foo.prototype.b ar=function()
{
print (this.b);
}
function test() {
var foo=new Foo("bar");
foo.bar(); // print bar
// bind method - is there a simpler way ????
var x=function(y){v ar z=y;return function(){z.ba r();}}(foo);
x(); // print bar
}
test();
Comment