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 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2009
    Location
    Newport Beach, California
    Posts
    96
    Thanks
    11
    Thanked 1 Time in 1 Post

    Newbie question about using arrays as objects

    hi.

    i know a little php, but new to javascript. much of the syntax is identical.

    i'm reading the new rhino book (flanagan 6th).

    in it, where he introduces METHODS, he says "When we combine FUNCTIONS with OBJECTS we get METHODS". Then he creates an empty ARRAY:

    Code:
    var a = [];
    then he uses the "push() method" to add elements to the array.

    Code:
    a.push(1,2,3);
    uh, methods are for *objects* right? Yet he is using them on an ARRAY.

    Can somebody help me see the light on how an array can magically becomes an object that is manipulated by a "method"?

    I mean, the array is still an array, no? It never actually becomes an object, right? Yet we still use a *method* to manipulate it. See my conceptual quandry?
    Last edited by PonchoX; 07-03-2011 at 11:05 PM.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    It does not magically become an object, it is an object

    See for yourself
    Code:
    var a = [];
    alert(typeof a);
    You will get "object"


  •  

    Posting Permissions

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