I like to use 'this' statement for all non-local variables: for properties, for class variables, etc. I do this for code easy reading, easy understanding where from this variable has got.
object someVar;
object SomeProperty { get; set }
void SomeMethod(object arg1, object arg2)
{
this.SomeProperty = arg1;
this.someVar = arg2;
}
...
I stumbled upon this piece of code
this seems totaly broken to me, but it does happen that "this" is null. I just don't get how this can be null
it is inside a normal method call such as
myObject->func();
inside MyObject::func() we have
if (!this) { return false; }
is there any way I can have the first line to throw a NullPointer...
The behavior of "this" when function bar is called is baffling me. See the code below. Is there any way to arrange for "this" to be a plain old js object instance when bar is called from a click handler, instead of being the html element?
// a class with a method
function foo() {
this.bar(); // when called here, "this" is the foo...
From what I gather as a Java beginner, when accessing instance members, the "this" keyword may apparently be used, but is not mandatory.
I wonder whether there is any official recommendation of sorts of a style guide (though I was unable to find anything in the actual Java style guide).
How do people usually do this, or is there maybe...
hi all,
I am dealing with a race condition, I believe, in my JAVA GUI.
I have some methods that create an "anonymous method" inside an anonymous class like this:
synchronized foo()
{
someMethod(new TimerTask()
{
public synchronized run()
{
//stuff
}
};
}
QUESTION: is that...
Possible Duplicate:
When do you use the this keyword?
Hello,
I understand that the "This" keyword is used to refer to an instance of the class, however, suppose I have a class called Life, which defines two fields, the person (their name) and their partner(their name):
class Life
{
//Fields
private string _person;
...
I've come across several instances of C# code like the following:
public static int Foo(this MyClass arg)
I haven't been able to find an explanation of what the this keyword means in this case. Any insights?
...
I have this code:
$("div[id^='intCell']").mouseover(function() {
$(this).css({ "border:","1px solid #ff097c"});
}).mouseout(function() {
$(this).css({"border:","1px solid #000"});
})
But I can't get it to work! In the html there is a list of divs which are generated by php to have ids of intCell_1, intCell_2 etc.
Any ideas?
...
I have code that looks like this:
template<class T>
class list
{
public:
class iterator;
};
template<class T>
class list::iterator
{
public:
iterator();
protected:
list* lstptr;
};
list<T>::iterator::iterator()
{
//???
}
I want to make the constructor of list::iterator to make iterator::lstptr point to the list it's ...
I'm using jQuery and I have a function that serves as an event callback, and so in that function "this" represents the object that that captured the event. However, there's an instance where I want to call the function explicitly from another function - how do I set what "this" will equal within the function in this case?
For example:
...
I have some jQuery code that highlights a link when clicked, and changes the font size and color of certain links on the page. My problem is that some of the functions in my jQuery are executing on ALL the links on the site, rather than just the ones in the div that I am trying to target.
Here's my code so far:
$(document).ready(f...
The error occurs when I try to do this
friend std::ostream& operator<<(std::ostream& os, const hand& obj)
{
return obj.show(os, obj);
}
where hand is a class I've created, and show is
std::ostream& hand::show(std::ostream& os, const hand& obj)
{
return os<<obj.display[0]<<obj.display[1]<<obj.display[2]<<obj.display[3]<<obj.di...
This bothers me a lot and I find I write stupid bugs when combined with Intellisense (VS 2008 Pro):
class Foo
{
public Foo(bool isAction)
{
this.IsAction = IsAction;
}
public bool IsAction { get; private set; }
}
Did you catch it? I certainly didn't until IsAction never changed, causing bugs.
Intellisense so...
I have a PHP class with a static function:
<? echo view::getUserSelector() ?>
Which outputs:
<div id="user_selector">
<div class="user">
<h1>Username1</h1>
<a href="javascript:selectUser(this);">select</a>
</div>
<div class="user">
<h1>Username2</h1>
<a href="javascript:selectUser(this);">s...
When should I explicitly write this->member in a method of
a class?
...
I'm coming from a Java background, with its class-based inheritance model, trying to get my head around Javascript's prototype-based inheritance model. Part of what is throwing me off, I think is that I have Java's meaning of "this" solidly in mind - and Javascript's "this" is a very different beast. I understand that Javascript's "thi...
I have something like this:
var Something = function(){
this.render = function(){};
$(window).resize(function(){
this.render();
});
}
The trouble is that inside the anonymous function 'this' refers to the window object. I know I could do something like:
var Something = function(){
this.render = function(){};
var tempThi...
var UI$Contract$ddlForm_change = function() {
debugger;
//'this' is currently the drop down that fires the event
// My question is can I change the context so "this" represents another object?
this = SomeObject;
// then call methods on the new "this"
this.someMethod(someParam);
};
is this possible?
Thanks,
~ck in San Di...
Hello,
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").click(function() {
$("form").each(function() {
this.reset();
});
});
Notice in the first example, we use $(this) to app...
I'm dealing with a large code base that uses the following construct throughout
class MyClass
{
public:
void f(int x);
private:
int x;
};
void MyClass::f(int x)
{
'
'
this->x = x;
'
'
}
Personally, I'd always used and hence prefer the form
class MyClass
{
public:
void f(int x);
private:
int _x;
};
void MyClass::f(int x)...