[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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2017-10-22 [AngularFire] Angular File Uploads to Firebase Storage with Angular control value accessor
2017-10-22 [Angular] Create a custom validator for template driven forms in Angular
2016-10-22 [RxJS] Stopping a shared observable execution
2016-10-22 [Angular 2] Share Template Content In Another Template With Content Projection <ng-content>