this

Using 'this' as a parameter to a method call in a constructor

I have a constructor like as follows: public Agent(){ this.name = "John"; this.id = 9; this.setTopWorldAgent(this, "Top_World_Agent", true); } I'm getting a null pointer exception here in the method call. It appears to be because I'm using 'this' as an argument in the setTopWorldAgent method. By removing this method call everythi...

jQuery multiple radio buttons

New to javascript/jquery and having a hard time with using "this" or "$(this)" to get the current object. I have a table with a set of radio buttons on each row, each named 's_'. None of the radio buttons are checked by default: <tr> <td align="left" style="width: 300px"> <div id="div_s_0"> <input type="radio" name="s...

How do I access 'this' from within a C# extension method?

I've been working with Vector2's and XNA, and I've come to find that calling the Normalize() member fuction on a Zero Vector normalizes it to a vector of {NaN, NaN}. This is all well and good, but in my case I'd prefer it instead just leave them as Zero Vectors. Adding this code to my project enabled a cute extension method: using Ext...

$(this) selector and children?

I'd like to use a selector to select the child img of the div I'm clicking on this example: <div id="..."><img src="..."></div> To get the div, I've got this selector: $(this) How do I get the img with a selector? ...

Is it true that using "this." before the parameters in c# uses more memory?

than just to call the parameter as it is? ...

smart pointers + "this" considered harmful?

In a C++ project that uses smart pointers, such as boost::shared_ptr, what is a good design philosophy regarding use of "this"? Consider that: It's dangerous to store the raw pointer contained in any smart pointer for later use. You've given up control of object deletion and trust the smart pointer to do it at the right time. Non-sta...

jQuery: exclude $(this) from selector.

Hi. I have something like this: <div class="content"> <a href="#">A</a> </div> <div class="content"> <a href="#">B</a> </div> <div class="content"> <a href="#">C</a> </div> When one of these links is clicked, I want to perform the .hide() function on the links that are not clicked. I understand jQuery has the :not selecto...

Passing "this" to a function from within a constructor?

Can I pass "this" to a function as a pointer, from within the class constructor, and use it to point at the object's members before the constructor returns? Is it safe to do this, so long as the accessed members are properly initialized before the function call? As an example: #include <iostream> class Stuff { public: static void...

What is the use of "delete this" ?

Today, I have seen some legacy code. In the destructor there is a statement like "delete this". I think, this call will be recursive. Why it is working? I made some quick search on Y!, I found that if there is a need to restrict the user to create the stack object, we can make destructor private and provide an interface to delete the in...

Javascript: how to set "this" variable easily?

I have a pretty good understanding of Javascript, except that I can't figure out a nice way to set the "this" variable. Consider: var myFunction = function(){ alert(this.foo_variable); } var someObj = document.body; //using body as example object someObj.foo_variable = "hi"; //set foo_variable so it alerts var old_fn = someObj.fn...

Javascript `this` not working as I thought?

I'm adapting a pretty basic js function into a class. Anyway, basically it just creates a floating container above the main page. I'm aware it's incomplete, but I'm in the middle of typing it up, and keep getting caught out when attempting to call the close() function. Firefox returns a this.sdiv is undefined. I'm confused as to how thi...

Common Event Handlers in VB.NET

I have around 10 buttons on my form and I want them to call the same Click event handler. But for that I need the Event handler to be generalized and we don't have "this" keyword in VB.NET to refer to the control that caused the event. How do I implement the functionality of "this" keyword in VB.NET? I want to be able to write an Even...

The use of "this" in Java

Hello, I have a question about the use of "this" in Java. If I write the following class: public class Example { int j; int k; public Example(int j, int k) { j = j; k = k; } public static void main(String[] args) { Example exm = new Example(1,2); System.out.p...

Using "this" with methods (in Java)

Exact duplicate by same poster: http://stackoverflow.com/questions/516291/the-use-of-this-in-java Hello, what about using "this" with methods in Java? Is it optional or there are situations when one needs to use it obligatory? The only situation I have encountered is when in the class you invoke a method within a method. But it is op...

Controlling the value of 'this' in a jQuery event

I have created a 'control' using jQuery and used jQuery.extend to assist in making it as OO as possible. During the initialisation of my control I wire up various click events like so jQuery('#available input', this.controlDiv).bind('click', this, this.availableCategoryClick); Notice that I am pasing 'this' as the data a...

Should objects delete themselves in C++?

I've spent the last 4 years in C# so I'm interested in current best practices and common design patterns in C++. Consider the following partial example: class World { public: void Add(Object *object); void Remove(Object *object); void Update(); } class Fire : Object { public: virtual void Update() { if(age ...

Javascript 'this' question

I have the following: var o = {f: function(fn) { fn.call(o); }}; var ob = {f: function() { o.f(function() { this.x = 2; //HERE: how can this reference ob? //ob.x = 2; }); }}; ob.f(); ob.x; // undefined o.f(fn) calls fn where this is bound to o. At HERE, I want to use this to access ob. However, when ob.f i...

Smart Pointers with "this" in C++

I have been working on replacing raw pointers with reference-counted pointers that expose only a const version of the underlying one. My objective is to reduce memory usage (and time spent unnecessarily constructing and destructing complex objects) without putting myself in a situation where any code has access to memory that it does no...

FireFox this Function...

Why does Firefox not handle this. This code works in IE. <%@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <script type='text/javascript'> function drvFunc(elem) { var e = elem.name; var d = "document." var f = "frm"; var str = d+"."+f+"."+e+".value;"; ale...

Why 'this' is a pointer and not a reference?

I was reading the answers to this question C++ pros and cons and got this doubt while reading the comments. Why the this is a pointer a not a reference ? Any particular reason for making it a pointer? ...