This is a migrated thread and some comments may be shown as answers.

[Solved] Object / Event Scope Problems

1 Answer 121 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 12 Aug 2009, 09:01 AM
Hi all,

i've a general Problem with JavaScript Scopes.
In our Application we us a JavaScript Object. This is a simple Version of this Object:

function FilterTree(srcTree) { 
  this.init(srcTree); 
 
FilterTree.prototype = { 
  _srcTree: null, 
  _dstTree: null, 
  init: function(srcTree){ 
    this._srcTree = srcTree; 
    this._srcTree.add_nodeChecked(this.otherFunction); 
  }, 
  srcTree_nodeChecked: function(){ 
    alert('srcTree_nodeChecked:  called'); 
    this.otherFunction(); 
  }, 
  otherFunction(){ 
    alert('otherFunction called'); 
  } 


So what we do is passing a RadTreeView Object to our Object Constuctor/init Function.
Then we want that our srcTree_nodeChecked Function is called when a Node is checked in the tree. Until here this works fine.
But
Our srcTree_nodeChecked function runs in another Scope. The function cant access the 'otherFunction' via 'this.otherFunction()';
This results in the ErrorMessage  'this.otherFunction is undefined.

Does someone know, how i can solve this probblem?

Thank you

regards

Alex

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 14 Aug 2009, 08:37 AM
Hello Alex,

You can manipulate the scope using call()/apply() - more info on this article:
http://www.digital-web.com/articles/scope_in_javascript/

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
General Discussions
Asked by
Alexander
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or