calling a function from a different context using javascript? -



calling a function from a different context using javascript? -

im trying phone call function/method in javscript using oop style different context.

for example:

var someclass = function(){ this.init = function(){ var = "an interesting variable"; this.foo(something); //this works fine }, this.foo = function(bar){ alert(bar); } this.foo2 = function(){ this.foo(something); // deos not work/ not defined } }; var newclass = new someclass(); newclass.init(); newclass.foo2();

so want phone call this.foo() function within this.foo2() context, acting this.init(), im not sure makes sense, im new oop in javascript.

your context right, you're trying access variable isn't defined in scope. variable something, declared var within init live within function.

you need create fellow member of someclass:

this.init = function() { this.something = 'an interesting variable'; this.foo(this.something); }, this.foo2 = function() { this.foo(this.something); }

javascript

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -