All Questions

634
votes
5answers
163911 views

How to access the correct `this` inside a callback?

I have a constructor function which registers an event handler: function MyConstructor(data, transport) { this.data = data; transport.on('data', function () { alert(this.data);...
881
votes
19answers
277407 views

How does the "this" keyword work?

I have noticed that there doesn't appear to be a clear explanation of what the this keyword is and how it is correctly (and incorrectly) used in JavaScript on the Stack Overflow site. I have witnesse...
665
votes
13answers
94390 views

Use of 'prototype' vs. 'this' in JavaScript?

What's the difference between var A = function () { this.x = function () { //do something }; }; and var A = function () { }; A.prototype.x = function () { //do something };
26
votes
6answers
5973 views

Javascript: Do I need to put this.var for every variable in an object?

In C++, the language I'm most comfortable with, usually one declares an object like this: class foo { public: int bar; int getBar() { return bar; } } Calling getBar() works fine (ignoring t...
891
votes
6answers
241046 views

'this' vs $scope in AngularJS controllers

In the "Create Components" section of AngularJS's homepage, there is this example: controller: function($scope, $element) { var panes = $scope.panes = []; $scope.select = function(pane) { ang...
218
votes
7answers
59637 views

When to call activity context OR application context?

There has been a lot of posting about what these two contexts are.. But I'm still not getting it quite right As I understand it so far: Each is an instance of its class which means that some programm...
471
votes
7answers
474092 views

jQuery: What's the difference between '$(this)' and 'this'?

I am currently working through this tutorial: Getting Started with jQuery For the two examples below: $("#orderedlist").find("li").each(function (i) { $(this).append(" BAM! " + i); }); $("#reset...
159
votes
5answers
109520 views

Pass correct "this" context to setTimeout callback?

How do I pass context into setTimeout? I want to call this.tip.destroy() if this.options.destroyOnHide after 1000 ms. How can I do that? if (this.options.destroyOnHide) { setTimeout(function() {...
284
votes
6answers
86181 views

What does 'var that = this;' mean in JavaScript?

In a JavaScript file I saw: function Somefunction(){ var that = this; ... } What is the purpose of declaring that and assigning it to this?
386
votes
7answers
185874 views

Difference between getContext() , getApplicationContext() , getBaseContext() and "this"

What is the difference between getContext() , getApplicationContext() , getBaseContext() , and "this"? Though this is simple question I am unable to understand the basic difference between them. Ple...

Previous Next