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 > All Constructor Instances Have Constructor Properties t...

All Constructor Instances Have Constructor Properties that Point to Their Constructor Function

When any object is instantiated, the constructor property is created behind the scenes as a property of that object/instance. This points to the constructor function that created the object. Below, we create an Object() object, stored in the foo variable, and then verify that the constructor property is available for the object we created.

Live Code

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

var foo = {};

console.log(foo.constructor === Object) /* logs true, because object() 
                                        constructed foo */
console.log(foo.constructor) // points to the Object() constructor function

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

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

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

  

Start a Free Trial


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