Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Jun 2011
    Posts
    119
    Thanks
    43
    Thanked 0 Times in 0 Posts

    question concerning a program code

    what does this code mean "obj.to"?
    The code is here -
    Code:
     clearTimeout(obj.to);
    I just want to know what does "to" mean here?

  • #2
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    I don't think it's a reserved/key word. it could be whatever was assigned to it in function obj()

  • #3
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    Code:
    function LengthOfSomething(){
     this.from = 0;
     this.to = 10;
     }
    obj = new LengthOfSomething()
    alert(obj.to)  //this will alert "10"

  • Users who have thanked blaze4218 for this post:

    ippo (09-27-2011)

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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:
    Code:
    obj.to=function(){return setTimeout('something',delay)}
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    ippo (09-27-2011)

  • #5
    Regular Coder
    Join Date
    Jun 2011
    Posts
    119
    Thanks
    43
    Thanked 0 Times in 0 Posts
    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!!
    Can you please clarify?

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,732
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    to is not a keyword. Read Kor's post #4 again.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    like Kor mentioned, it is most likely a custom property/method.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #8
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    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 liberties so bear with me.

    In the code you provided:
    Code:
     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:
    Code:
    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 :
    Code:
    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...
    Code:
    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:
    Code:
    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...

  • Users who have thanked blaze4218 for this post:

    ippo (09-27-2011)

  • #9
    Regular Coder
    Join Date
    Jun 2011
    Posts
    119
    Thanks
    43
    Thanked 0 Times in 0 Posts
    Blaze4218 that was an excellent explanation that cleared all my doubts

  • #10
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by blaze4218 View Post
    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
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #11
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    And your right Kor but:
    Quote Originally Posted by blaze4218 View Post
    I may take some pragmatic 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)

  • #12
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I didn't mean to sound like a reproach tone, because:
    Quote Originally Posted by Kor
    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
    Last edited by Kor; 09-27-2011 at 03:24 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #13
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    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*
    Quote Originally Posted by Kor View Post
    I only sensed that the term instance was not used properly in the context
    But I assure you, I took no offense.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •