this

How does the system know what to use when 'this' keyword is used?

How does the system know what to use when 'this' keyword is used? Recently, I was asked this question in an interview. Having never thought about this, I replied back saying that the system will know the current context in which the flow of control is and decide the object to be used instead of this. The interviewer didn't look pleased ...

Hide all but $(this) via :not in jQuery selector

Advanced title, simple question: How to do the following in jQuery: $("table tr").click(function() { $("table tr:not(" + $(this) + ")").hide(); // $(this) is only to illustrate my problem $("table tr").show(); }); Thanks in advance! ...

The best way to handle a change in 'this'

A problem I regularly come across writing javascript using jQuery is that when a method of an object involves adding an event listener 'this' changes from being a reference to the object, to being a reference to the DOM element that triggered the event. Currently if I want to refer to the object from within the event handler I do someth...

What exactly is the 'this' reference in as3 classes?

I have searched up and down the internet for even the slightest mention of the 'this' reference, and have found NOTHING!!! Nobody seems to talk about 'this' at all. I'm an experienced c++ programmer, so I am more than familiar with the idea of a 'this' pointer/reference. My question is just what exactly is the 'this' reference in an a...

"this" keyword in event methods when using JavaScript prototype object

Hi everyone, I'm trying to access the member variables of a prototype class in JavaScript in an event handler -- something I'd typically use the "this" keyword for (or "that" [copy of this] in the case of event handlers). Needless to say, I'm running into some trouble. Take, for example, this HTML snippet: <a id="myLink" href="#">My L...

How to make the following jQuery snippet work?

var func = function() { $(this).hide(); $parent = $(this).parent(); $parent.removeClass('my_signature_mouseover'); var text = $(this).val(); var $span = $("#status span"); $span.text(text); $span.show(); }; $("#status input").keyup(function (e) { var keyCode = e.keyCode || e.which; if (keyCode == 13) {...

Jquery AJAX call: $(this) does not work after success

Hi, I am wondering why $(this) does not work after a jQuery ajax call. My code is like this. $('.agree').live("click", function(){ // use live for binding of ajax results var id=($(this).attr('comment_id')); $.ajax({ type: "POST", url: "includes/ajax.php?request=agree&id="+id, success: function(response) { ...

jQuery - IE6,7 not suporting $(this) ?

Hey, I have a code, that works in all modern browsers, but not in IE 6,7. $('.cat1').toggle(function() { $(this).parent('li').next('ul').slideUp(); $(this).css('background-position', '0px 0px'); return false; }, function() { $(this).parent('li').next('ul').slideDown(); $(this).css('background-position', '-210px...

What does the variable $this mean in PHP?

I see the variable $this in PHP all the time and I have no idea what it's used for. I've never personally used it, and the search engines ignore the "$" and I end up with a search for the word "this". Not exactly what I wanted. So, can anyone tell me? ...

Jquery $this or each() to specify one link at a time

Im finding jQuery to difficult to learn as there seems to be many ways to write the same thing. As an exercise I would like to take the text within anchor tags and stuff it into the links href attribute. eg <a href="">http://www.something.com&lt;/a&gt; to become <a href="http://www.something.com"&gt;http://www.something.com&lt;/a&g...

JS Object this.method() breaks via jQuery

I'm sure there's a simple answer to this, but it's Friday afternoon and I'm tired. :( Not sure how to explain it, so I'll just go ahead and post example code... Here is a simple object: var Bob = { Stuff : '' , init : function() { this.Stuff = arguments[0] } , doSomething : function() { console.log( this.Stuff ); } } An...

Getting the original this in an object for jQuery event handlers etc. when using class inheritance

I know that jQuery isn't designed for working with a class-like model but I really could do with being able to extend a base class as that fits my needs perfectly. I started by just doing the following: jQuery.myBase = { foo: 'bar', bar: function() { ... } } jQuery.fn.myPlugin = function() { $.extend( this, jQuery.myBase, {...

JQuery: referring to the right "this"

I'm trying to write a very simple plugin that on anchor mouseover increases the respective anchor text size and on mouseout removes the anchor. The problem is that I can't get the right "this". so i have: (function($){ $.fn.extend({ //function name textOverlay : function(){ //return return this.each(function(){ var cucu ...

How to get the "this" (scope) of a Javascript anonymous function?

Let's say I get an anonymous function an need to act on its context, but it's different whether it's binded to "window" or an unknown object. How do I get a reference to the object an anonymous function is called from? EDIT, some code : var ObjectFromOtherLibIAmNotSupposedToknowAbout = { foo : function() { // do something ...

Other usage of the this keyword in Java

(For those who read my previous question, this is the same teacher and the same project.) My teacher 'inspected' my code for a web application project and provided some suggestions. One of the suggestions was to use the this keyword even in this situation: private String getUsername() { return username; } So if I follow his advic...

Javascript: attaching OOP methods to events and the 'this' keyword

I am new to OOP Javascript and am having trouble with the this keyword and events. What I'm trying to achieve is: I have multiple DOM objects and want to not only bind a common event to them, but keep some data about the aforementioned objects in a global container (to increase runtime performance). So what I do is basically this: f...

[C++] the "this" pointer inside a class

Hi, the question is simple... is there any difference in using this->yourvariable or yourvariable directly for some reason? I am not finding any problem with that, but I am using this-> a lot and would like to know if there is any difference before going further. I saw a comment on a post here and I don't remember which thread, but th...

What is the this[''] accessor that shows up in Drools

Just looking for a way to pass parameters into a getter in Drools... I have noticed in Eclipse Ganymede that intellisense is helpful in determining the getters that can be used to select an entity in a Drools WHERE clause. Just type a letter and hit ctrl+Space to see the list. I have another project in Drools.NET that relies on C# Pro...

Access protected member of a class in a derived class

Hi ho, i have an old codebase here, where they used protected member variables. Whether or not this is a good idea can be discussed. However, the code must have compiled fine with gcc3. I have a derived template class Bar that uses protected member x from class template Foo like so template <class Something> class Foo { public: //...

determining $(this) in jquery

A common issue I have is getting confused what $(this) is referring to. I often will try to give it some odd style: $(this).css("border","10px solid red") Which helps sometimes. I'm stumped with the following however. My question can maybe be answered in two ways: 1) is there a universal way to 'see' what $(this) is referring to in...