runeveryday Posted July 2, 2010 Share Posted July 2, 2010 i have read this on the interent" function getArea(radius) { // return the radius of our circle using the // PI attribute of the built-in Math object return (radius * radius) * Math.PI; } var circle = { radius : 9, getArea : getArea(this.radius) }; Imagine we want to create lots of circle objects using our object as a base - if we’ve declared using the object literal, we’re not able to do that. the new operator creates an instance of any built-in or user-defined object - basically allowing us to re-use a user-defined object. can't understand on the above that we declare using the object literal not able to do that. Quote Link to comment Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 An 'object literal' (AKA JSON), allows you to write the object kind of in-line. You don't pre-define it like functions, which means you can't create multiple instances of it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.