javascript - Calling function from another scope -


i have following function in javascript:

function jscontroller() {    this.foo = function() {       $("body").click(function() {          $(this).externalfunction();        }    };    this.externalfunction = function() {       alert('a');    }; } 

it doesn't work, says externalfunction() undefined.

how can solve this?

in case: $(this).externalfunction() this object scoped $("body") element. solve it:

function jscontroller() {    var self = this;    this.foo = function() {       $("body").click(function() {          self.externalfunction();        }    };    this.externalfunction = function() {       alert('a');    }; } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -