Jump to content

Obj1=new Object()


Drycodez

Recommended Posts

If you use the built in object constructor called Object() (as in your example) I think there is no difference. If you create a unique object, your constructor function will need a return statement to be used without the new keyword.

Link to comment
Share on other sites

There's also a faster way to create objects:var cars = {BMW:"M3",Dodge:"RAM",Mercedes:"CLK"};I believe the above is known as 'literal' way of doing it?

c=Object;c.txt='string3'

what about the above? why is it that no brackets preceed it?

Link to comment
Share on other sites

c=Object;c.txt='string3'

It's not what you think. The first statement creates a function called c. It is identical to the function called Object. Because a function is also an object, you can arbitrarily assign it properties. That is what you have done in the second statement. The result is a copy of the Object function with a property called txt. If you try this:

alert(typeof c)

The alert will print "function" not "object"

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...