I have a constructor function which registers an event handler:    function MyConstructor(data, transport) {     this.data = data;     transport.on('data', function () {         alert(this.data);     }); }  // Mock transport object var tran...
What's the difference between  var A = function () {     this.x = function () {         //do something     }; };   and  var A = function () { }; A.prototype.x = function () {     //do something };...
In a JavaScript file I saw:   function Somefunction(){    var that = this;     ...  }   What is the purpose of declaring that and assigning this this to it?...
This question already has answers here:...
I need to access this from my setInterval handler  prefs: null, startup : function()     {         // init prefs         ...         this.retrieve_rate();         this.intervalID = setInterval(this.retrieve_rate, this.INTERVAL);     },  retrieve_ra...
The problem in example 1 is 'this' referring to the global name instead of the myName object.  I understand the use of bind() in setting the value of this to a specific object, so it solves the problem in example 1, but why does this proble...
I followed a tutorial for creating a JavaScript stopwatch and am trying to expand it to work with multiple stopwatches (multiple instances of a class).  The problem I have is when I am trying to display the current value while the clock is ticking...
I was wondering what the 'this' value (or invocation context) is of the forEach callback function. This code doesn't seem to work:  var jow = [5, 10, 45, 67];  jow.forEach(function(v, i, a){      this[i] = v + 1;  });  alert(jow);   Thx...
My question is:  function Foo() {    this.foo = "bar"; // <- What is "this" here? }   From what I can tell it depends on how Foo is used, i.e. as a constructor or as a function. What can this be in different circumstances?...
Suppose I have JavaScript code like         myClass = function(){           function doSomething(){               alert(this); // this1            }       }        alert(this); //this2   What those two 'this' objects are refer for??...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.