[Javascript] Replicate JavaScript Constructor Inheritance with Simple Objects (OLOO)
Posted Answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Javascript] Replicate JavaScript Constructor Inheritance with Simple Objects (OLOO)相关的知识,希望对你有一定的参考价值。
Do you get lost when working with functions and the new keyword? Prototypal inheritance can be completely replicated without either of those two concepts. In this lesson we will convert an object created from the new keyword against a function, to simply objects linked to other objects.
Sometime If you find yourself doing `new` too much, for example:
function House(color){ this.color = color } const myHouse = new House(‘white‘) console.log(myHouse.color) // white
It is possible just using Object, instead of constructort:
const house = { set houseColor(color){ this.color = color } } const myHouse = Object.create(house) console.log(myHouse) // {color: ‘white‘}
Our end result is the same. We didn‘t have worry about creating a function and calling it with the new
keyword. This pattern is called OLOO
, or objects linking to other objects.
Since prototypes are simply objects, objects can be created in a manner so that they‘re easily delegated as prototypes of other objects. Object.create
gives us the ability to easily create new objects that have specifically delegated prototype objects.
以上是关于[Javascript] Replicate JavaScript Constructor Inheritance with Simple Objects (OLOO)的主要内容,如果未能解决你的问题,请参考以下文章
replicate-wild-do-table与replicate-wild-ignore-table
关于replicate_do_db和replicate_ignore_db的坑
mysql 复制参数replicate_do_db和replicate_ignore_db介绍
MyEcplise导入项目报错:Errors running builder 'JavaScript Validator' on project '项目名'. ja