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
Post a Comment