...

View Full Version : question concerning a program code



ippo
09-26-2011, 01:17 PM
what does this code mean "obj.to"?
The code is here -


clearTimeout(obj.to);

I just want to know what does "to" mean here?

blaze4218
09-26-2011, 01:45 PM
I don't think it's a reserved/key word. it could be whatever was assigned to it in function obj()

blaze4218
09-26-2011, 01:48 PM
function LengthOfSomething(){
this.from = 0;
this.to = 10;
}
obj = new LengthOfSomething()
alert(obj.to) //this will alert "10"

Kor
09-26-2011, 02:20 PM
obj must be the reference of an element/object. A variable
to must be a property, a custom property, of that element, previously created.

Could have been:


obj.to=function(){return setTimeout('something',delay)}

ippo
09-27-2011, 07:27 AM
Thanks Blaze & Kor.
I thanked you both for helping me out. :)
But i don't get any reference of obj.to property or the "to" keyword in any javascript book .,neither I get in google search!!
There is no reference of the 'to' or 'from' words in any javascript book!!
I even searched the Net and also indexes of all the popular books on Javascript but nowhere is there any reference of such a word!! :confused:
Can you please clarify?

Philip M
09-27-2011, 08:25 AM
to is not a keyword. Read Kor's post #4 again.

Dormilich
09-27-2011, 08:26 AM
like Kor mentioned, it is most likely a custom property/method.

blaze4218
09-27-2011, 08:34 AM
My point was that it is not a keyword, its just a property of an object constructor (try googling that, or try http://www.javascriptkit.com/javatutors/oopjs2.shtml [pre-googled :)] )
I think you still need some clarification, so I'm gonna break it down a little the best I know how, I may take some pragmatic (http://en.wikipedia.org/wiki/Pragmatics) liberties so bear with me.

In the code you provided:

clearTimeout(obj.to);

The "obj" refers to an object.
The "to" refers to a property of the object "obj"

Both of these are made up by the programmer. If I decide to make an object called "obj" all I need to do is this:


function LengthOfSomething(){
this.from = 0;
}
obj = new LengthOfSomething()


If you read it again you will notice that my object is created at the line obj = new LengthOfSomething()
This means that my object a.k.a. "obj" is a copy(of-sorts) of LengthOfSomething(). In JS we call this an instance. As in "obj is an instance of LengthOfSomething()".
My object also has a property. The "from" property is created in the line this.from = 0;
The important thing to understand here is that I didn't have to name my object "obj"! I could have named it "kjjrbds" but that would be hard to understand :( :


function LengthOfSomething(){
this.from = 0;
}
kjjrbds = new LengthOfSomething()

Also, I didn't have to name my property "from"! I could have named it "osdjok" but that would be hard to understand also...


function LengthOfSomething(){
this.osdjok = 0;
}
kjjrbds = new LengthOfSomething()

So now if I want to call the property I created for the object of my constructor I would have to remember all of this:


kjjrbds.osdjok()

And frankly, that's a mouthful. This is all just an absurd exaggeration/oversimplification of the key idea:

The code you gave "obj.to" was an instance (obj) of an object that had a made-up property (to). Your not going to find that in a google search because the programmer that made up that object did so for the code in that document. If someone else later used that same name, it would mean something completely different...
I didn't oversimplify this because I believe that you didn't understand any of that, I oversimplified because I don't know which parts you don't understand...

ippo
09-27-2011, 09:34 AM
Blaze4218 that was an excellent explanation that cleared all my doubts :thumbsup: :thumbsup: :thumbsup:
:)

Kor
09-27-2011, 10:07 AM
The code you gave "obj.to" was an instance (obj) of an object
Well, in fact javascript does not work with instances, or better say javascript makes no difference between objects and instances. In the example above I would have rather said that obj is the reference of an object.

In fact, in class oriented languages, an object is an instance of a class. But as javascript is not a class-oriented language, objects are here instances of a constructor (or instances of the object Object()), while the "inner structure" of the object is not given by a class, but by its prototype.

Shall I be excused, however, for being pedantic... :) I only sensed that the term instance was not used properly in the context :)

blaze4218
09-27-2011, 10:43 AM
And your right Kor but:

I may take some pragmatic (http://en.wikipedia.org/wiki/Pragmatics) liberties so bear with me.
and since I prefaced with the url to http://www.javascriptkit.com/javatutors/oopjs2.shtml I decided to stay close to that terminology (the best I could) so that it would not throw anyone off should they need to reference the link for further help. I actually checked back and forth many times to make sure the words I used matched (the best I could)

Kor
09-27-2011, 03:44 PM
I didn't mean to sound like a reproach tone, because:


Shall I be excused, however, for being pedantic... :)

You have no fault. I suppose that a lot of programmers (including the guys from Javascriptkit) forget sometimes that there is a subtle difference between a class-based language and a prototype-based languages, even if both are OO :)

blaze4218
09-27-2011, 03:53 PM
Your tone was fine. I figured that you were at worst only trying to include a thorough definition of the terms most appropriate to use so that anyone who did mix up the ideas could move forward with confidence in their understanding of the distinction (very appropriate for the tone of this thread). And at best you were just being *silly*

:) I only sensed that the term instance was not used properly in the context :)
But I assure you, I took no offense.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum