Introduction:
In this post we will talk about how to handle javascript objects.
On the bottom of this post you will find a jsbin that you can use to play with the code snippets below.
This post was inspired by this book: "Javascript: The good parts" by Douglas Crockford
This post was inspired by this book: "Javascript: The good parts" by Douglas Crockford
How to create new objects:
How to use inheritance:
The prototype link is only used in retrieval. If we look up a property that does not exist in the current object, the prototype link will be used to go up the chain looking if any of the parents has it.
Adding a new property to the parent object will cause to appear in the children but not the other way around.
Reflection and property deletion:
Also if you delete a property from the child and the parent has the same property, the parent's value will shine through.
Global scope problem:
Your Lab:
JS Bin
No comments:
Post a Comment