Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

1. JavaScript Objects > An Instance Created From a Constructor Can Have Its Own...

An Instance Created From a Constructor Can Have Its Own Independent Properties (Instance Properties)

In JavaScript, objects can be augmented at any time (i.e., dynamic properties). As previously mentioned, and to be exact, JavaScript has mutable objects. This means that objects created from a constructor function can be augmented with properties.

Below, I create an instance from the Array() constructor and then augment it with its own property.

Live Code

<!DOCTYPE html><html lang="en"><body><script>

var myArray = new Array();
myArray.prop = 'test';

console.log(myArray.prop) // logs 'test'

</script></body></html>

This could be done with Object(), RegExp(), or any of the other non-primitive constructors—even Boolean().


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint