Closed Thread Icon

Preserved Topic: What "this" (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18126" title="Pages that link to Preserved Topic: What &amp;quot;this&amp;quot; (Page 1 of 1)" rel="nofollow" >Preserved Topic: What &quot;this&quot; <span class="small">(Page 1 of 1)</span>\

 
Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-16-2001 15:51

What do the "this" command do?

i'm learing javascript that is why there is so many questions from mi!



[This message has been edited by Osaires (edited 08-16-2001).]

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-16-2001 16:16

Ooooh, that's sort of weird. Honestly, I don't completely understand it myself (hardly ever use it) but let me show you a quick example that may help explain:

-------

function coolObject()
{
this.iscool = true;
}

var myobject = new coolObject();

alert(myobject.iscool); // says "true"

-------

See, when the function is used as a constructor (to create a new object), "this" refers to the object that is being created. Now say you did this...

-------

function coolObject()
{
this.iscool = true;
this.changeCoolness = changeCoolnessFunction;
}

function changeCoolnessFunction()
{
this.iscool = !this.iscool;
}

var myobject = new coolObject();
alert(myobject.iscool); // says "true"
myobject.changeCoolness();
alert(myobject.iscool); // says "false"

So you see, I made it so that any coolObject has the method/function changeCoolness, which refers to the function changeCoolnessFunction, and "this" in the changeCoolnessFunction refers to the object that it's being operated on.

Pretty complicated. Hopefully I explained that correctly. =)

Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-16-2001 16:23

Hmmm i think i get it, just have to grumble on it, he he
think think (0010110011010011001111100011010)



Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 08-16-2001 17:18

A good example is the wonderful this.className (works in IE5 [4?] and NS6), e.g.:

<td class="tdClass" onmouseover="this.className='tdOver'" onmouseout="this.className='tdClass'">Something</td>

It informs the browser that we do something to this whatever this is (my ability to explain seems to be deserting me - if your Aunt were to indicate a bowl of mashed potato, pos. with a bit of grated cheese on, and she said "take this to the table" you'd know what she meant without her having to explicitly tell you what the 'this' was she was refering to).

Hope that helps.

Emps

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-16-2001 17:24

Oh, yeah, that's another way it can be used. When used in an event handler for an HTML element, it refers to the HTML element itself.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 08-16-2001 17:46

Ultimately it isn't too tricky it's just a way for an obect to refer to itself.




:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-16-2001 18:09

Just a nother question, how did Doc get the icon of the www.ozoneasylum.com to look like that, not the ordenary E icon



Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 08-16-2001 18:18

http://www.gurusnetwork.com/tutorials/misc/index.html - at the bottom.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-16-2001 18:48

That icon thing must be an IE 5.5 feature, 'cause it doesn't seem to work in 5.0.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 08-16-2001 19:30

It should work in IE5+ (or so it says at favicon.com). I have noticed that it is often difficult getting it to appear so there might be a caching problem or some other problem that I'm not aware of.

If you are only using IE5.0 you should see what they've done to the [scroll] bars in this place.

Emps

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-16-2001 19:39

No, the scroll bar colors is definitely IE5.5+, no 5.0.

Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-16-2001 19:51

Pleas late me know if I ask to much just wondering how that ?round? command work
Is it possible to round a variable with the value of 4.7 to 5 ?





[This message has been edited by Osaires (edited 08-16-2001).]

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-16-2001 20:04

Not a problem, ask all you want, you ask fun questions to answer. =)

The Math object contains lots of functions helpful for working with numbers. In this case, you want:

Math.round(number)

So...

Math.round(4.7) will return 5.

Also helpful at times is Math.floor(number) and Math.ceil(number). Floor always rounds towards negative infinity and ceil (short for "ceiling") rounds towards positive infinity. (That basically means Floor rounds down and Ceil rounds up, but saying that can confuse you when you're working with negative numbers.)

So... Math.floor(4.7) returns 4.
but... Math.floor(-4.7) returns -5, since it rounds towards negative infinity.

There ya go! =)

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 08-16-2001 20:52

'this' is a reference to the current working object.

It is a throw back to other languages which then tend to be more useful with.

An example in java.

public class Addition {

int value = 0;
int value2 = 1;

public int add() {
int total = this.value + this.value2;
}
}

Instead of using 'this' you could leave it out.

public class Addition {

int value = 0;
int value2 = 1;

public Addition() {}

public int add() {
return value + value2;
}
}

However it can get tricky when you have to objects with different values.

Say I have a main method, and an add2 method.

public int add2 (Addition x) {
return this.value + x.value;
}

public static void main(String[] args) {
Addition addition1 = new Addition();
Addition addition2 = new Addition();

Addition1.add2(addition2);
}

I think in the above example you will see where 'this' becomes important.

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 08-16-2001 21:12

Slime -

It's a 5.0+ feature, although Microsoft really bungled it. In order to get it to display, remove ANY bookmarks for the site, and clear the cache and history. Then visit the site and bookmark. It should show up. But that leads to another problem. Clear the cache again and it's GONE. Why would MS do it THAT way?

Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-17-2001 01:22

Didn?t get it to work me eider, maybe I just tray the page on a another computer





[This message has been edited by Osaires (edited 08-17-2001).]

« BackwardsOnwards »

Show Forum Drop Down Menu