In this example, when we call the toString() method on the person object, the JavaScript engine finds it in the person object. Therefore, a method is a property with value as a function. Note that when a function is a value of an object’s property, it’s called a method. The toString() method returns the string representation of the person object. If the JavaScript engine cannot find the property in the object’s prototype, it’ll search in the prototype’s prototype until either it finds the property or reaches the end of the prototype chain.įor example, you can call the toString() method of the person object like this: However, if you access a property that doesn’t exist in an object, the JavaScript engine will search in the prototype of the object. It returns the value of the name property as expected. The following example accesses the name property of the person object: When you access a property of an object, if the object has that property, it’ll return the property value. The prototype itself is an object with its own properties: When examining the person object in the console, you’ll find that the person object has a property called prototype denoted by the ]: Let person = Code language: JavaScript ( javascript )
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |