[thelist] [javascript] object literal question

Tom Dell'Aringa pixelmech at yahoo.com
Wed Mar 8 09:41:23 CST 2006


Say I have this object literal:

var PricedProduct = {
  name:null,
  price:0,
  toggle:0,

  add:function(pname, pprice, ptoggle){
    this.name = pname;
    this.price = pprice;
    this.toggle = ptoggle;
  }
}

And say I add 3 products, which by name are "widge1", "widge2" and "widge3". This is probably
painfully obvious to someone, but how to I access the properties of say "widge2"? What tells me
how many objects I have? 

I figured I could make an array add push() the new product name to it each time I run the add()
method so I have an array with all the names (so I know I have 3 products by testing
array.length). But even if I have the name, again, how do I grab that one particular object? Or am
I going about building this object the wrong way?

In the end, when a user prints a page I have to grab this list of products and write an invoice
out for each product that is toggled 'on' (or 1). I'd need to grab the name and price for each one
of these and build them into a table, which is why I am going down this path..

Tom

http://www.pixelmech.com/
http://www.crossandthrone.com/


Proponents of higher-order theories of consciousness argue that consciousness is explained by the relation between two levels of mental states in which a higher-order mental state takes another mental state. If you mention this to Chuck Norris, expect an explosive roundhouse kick to the face for spouting too much fancy-talk.




More information about the thelist mailing list