this

difference between static_cast<const A>(*this) and static_cast<const A&>(*this)

in the following code ( taken from effective C++ ): class A { .... .... .... char& operator[](std::size_t position) // now just calls const op[] { return const_cast<char&>( // cast away const on // op[]'s return type; static_ca...

Errors with 'this' pointer

I'm having a problem with the this pointer inside of a custom class. My code looks as follows. class Foo(){ public: void bar(); bool baz(); }; bool Foo::baz(){ return true; } void Foo::bar(){ bool is_baz = (*this).baz(); } As I said above, I believe the error I'm getting (LNK2019) is coming from the this. I think it is l...

Cross Reference and Passing the This Pointer between Classes [NS2/C++]

------------ ------------ | TclObjct | | Handler | ------------ ------------ |__________________________________| | -------------- ...

Javascript and jQuery getting the right this

I have some sample code that looks like this: var myDrawingArea = new DrawingArea(document.getElementById("drawing_canvas")); function DrawingArea(aCanvas) { this.brushSize = 2; this.buildToolbar = (function () { $("#brush-size") .slider({ value: this.brushSize, // this is DrawingArea insta...

Jquery get all ... inside this or $(this)

how can i get for example all links inside a all ready selected jquery element (this) $("#container li").each(function(){ $("this a").each(function(){ // links inside this li element }); }); This does not work is there a other way? ...

How do I update the JavaScript this-pointer inside an object to point to another object?

hi guys, I'm having some trouble with JavaScript and the passing of a function as parameter of another function. let's say we are inside a class and do something like that: this.get('target').update(this.onSuccess, this.onFail); 'target' is a JavaScript-object that has a method called update() I'm calling this method and pass tow me...

Suggestions for dealing with `exports` in node.js

Theory: One of the things that appeals to me about node.js is using it as a command line tool. In theory, I can write libraries in Javascript and place them in my ~/.node_libraries directory, and then then I can reuse those libraries. So for instance, I have a text.js in ~/.node_libraries, and it has a bunch of text-related function...

"this" keyword inside closure

I've seen a bunch of examples but can't seem to get some sample code to work. Take the following code: var test = (function(){ var t = "test"; return { alertT: function(){ alert(t); } } }()); and I have a function on window.load like: test.alertT(); That all works fine. However, when I try...

Using *this in C++ class method to fully overwrite self instantiation

Is the following code safe? (I already know it compiles properly.) void Tile::clear() { *this = Tile(); } int main() { Tile mytile; mytile.clear(); } ...

C# static "this"

Is there a way in a C# static method to refer to the Type the method is defined in? In an instance method you can determine the type by: public void Foo() { Type type = this.GetType(); } how would it look like in a static method? public static void Bar() { Type type = ....? } Update: Sorry, clarification needed: I know the...

PHP Equivalent to Ruby's @instance_variable?

I was wondering if there is a shorter, better or cleaner way to assign and use class variables in PHP, then through $this->instance_variable ? class Bar { # internal variables var $foo = "Hello World"; public function foo() { return $this->foo; } } I am not very familiar with all PHP's variable scoping, but from what I u...

How do I redefine `this` in Javascript?

I have a function which is a JQuery event handler. Because it is a JQuery event handler, it uses the this variable to refer to the object on which it is invoked (as is normal for that library). Unfortunately, I need to manually call that method at this point. How do I make this inside the called function behave as if it were called from...

How can I use $(this) inside of Fancybox's onComplete event?

I'm trying to use jQuery's $(this) inside of Fancybox's onComplete event, but I'm running into trouble. Here's my javascript code: $('a.iframe').fancybox({ centerOnScroll: true, onComplete: function(){ var self = $(this); var title = self.title; alert(title.text()); } }); I have simplified the code abo...

Java - Leaking this in constructor

I'd like to avoid (most of the) warnings of Netbeans 6.9.1, and I have a problem with the 'Leaking this in constructor' warning. I understand the problem, calling a method in the constructor and passing "this" is dangerous, since "this" may not have been fully initialized. It was easy to fix the warning in my singleton classes, because...

php - unset $this

I've made a class that acts like an file wrapper. When user call delete method, i want to unset the object (actually $this). Is there a way (workaround) to do that? The manual said no, there is no way... ...

jQuery: how to get original value of this in methods

I'm trying to have some object oriented design using JS and jQuery. I have the following construstor: function A () { this.url = "some url"; $("rrr").autocomplete({ source: function(req, add){ $.getJSON(this.url, req, function(data) {} ... } As you guessed, I can't use this.url, since jQuery redefienes this. I can't u...

Passing self into a constructor in python

I recently was working on a little python project and came to a situation where I wanted to pass self into the constructor of another object. I'm not sure why, but I had to look up whether this was legal in python. I've done this many times in C++ and Java but I don't remember ever having to do this with python. Is passing references to...

$this vs function name

I am getting a hang of OOP and finally started creating them in my scripts. One thing I don't get it is the "$this" after creating an instance of class. For example, this guy coded: class Form { protected $inputs = array(); public function addInput($type, $name) { $this->inputs[] = array("type" => $type, "name" => ...

How does the Javascript "this" operator deal with scopes?

Edit: I have to apologize, the problem I posted about actually does not exist in the code I posted, because I oversimplified it. I'll try to post something later. Deletion would also be ok, but there are too many answers at present, so I cannot do it myself. Edit2: Ok, here goes: Let, function F() { this.field = "value" ; v...

How do I access class variables from an event in Javascript?

I'm using the prototype javascript libraries. My code is below. I've created a class and in that class I have created an event listener for one of the class methods. In that method I need to access both the attributes of the form element that triggers the event and the class properties. Currently, the code understands $(this).getValue...