Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-03-2011, 11:03 PM   PM User | #1
PonchoX
New Coder

 
Join Date: Apr 2009
Location: Newport Beach, California
Posts: 94
Thanks: 11
Thanked 1 Time in 1 Post
PonchoX is an unknown quantity at this point
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?
__________________
Radified

Last edited by PonchoX; 07-03-2011 at 11:05 PM..
PonchoX is offline   Reply With Quote
Old 07-04-2011, 06:46 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
It does not magically become an object, it is an object

See for yourself
Code:
var a = [];
alert(typeof a);
You will get "object"
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:40 AM.


Advertisement
Log in to turn off these ads.