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)的更多相关文章

  1. 深入浅析JavaScript中的constructor

    constructor 属性返回对创建此对象的数组函数的引用.本文给大家介绍JavaScript中的constructor ,需要的朋友参考下吧 定义和用法 constructor 属性返回对创建此对 ...

  2. JavaScript 系列--JavaScript一些奇淫技巧的实现方法(二)数字格式化 1234567890转1,234,567,890;argruments 对象(类数组)转换成数组

    一.前言 之前写了一篇文章:JavaScript 系列--JavaScript一些奇淫技巧的实现方法(一)简短的sleep函数,获取时间戳 https://www.mwcxs.top/page/746 ...

  3. JavaScript 对象JavaScript 对象

    JavaScript 中的所有事物都是对象:字符串.数值.数组.函数... 此外,JavaScript 允许自定义对象. 所有事物都是对象 JavaScript 提供多个内建对象,比如 String. ...

  4. JavaScript介绍-javaScript学习之旅(一)

    javaScript简介 1.javaScript是互联网上最流行的脚本语言,这门可用于web和html,更可广泛用于服务器端,pc端,移动端. 2.javaScript脚本语言: javaScrip ...

  5. 网页三剑客:HTML+CSS+JavaScript 之JavaScript

    JavaScript 简介 JavaScript 是互联网上最流行的脚本语言,这门语言可用于 HTML 和 web,更可广泛用于服务器.PC.笔记本电脑.平板电脑和智能手机等设备. JavaScrip ...

  6. javascript之 JavaScript 工具库

    javascript之 JavaScript 工具库jQuery 目录: 一.查找标签和事件绑定以及操作标签的对比 二.DOM对象和jquery的转换 三.$(document).ready( )  ...

  7. 非侵入式JavaScript(Unobtrusive javaScript)理解

    转载自 https://my.oschina.net/leegq/blog/279750 在Web的早期阶段,也就是在jQuery出现以前,在同一个文件中混杂JavaScript代码和HTML标记是非 ...

  8. How Javascript works (Javascript工作原理) (十一) 渲染引擎及性能优化小技巧

    个人总结:读完这篇文章需要20分钟,这篇文章主要讲解了浏览器中引擎的渲染机制. DOMtree       ----|   |---->  RenderTree CSSOMtree  ----| ...

  9. 【JavaScript】JavaScript基础

    JavaScript简介 JavaScript历史 在上世纪1995年,著名的互联网公司网景公司希望能在静态HTML页面上添加一些动态效果,于是叫Brendan Eich这哥们在两周之内设计出了Jav ...

随机推荐

  1. docker:安装mysql

    文章来源:https://www.cnblogs.com/hello-tl/p/9234429.html 1.添加镜像 docker pull mysql 2.在/data下新建文件夹mysql,进入 ...

  2. Linux服务器的弱口令检测及端口扫描

    一.弱口令检测--John the Ripper John the Ripper工具可以帮助我们扫描出系统中密码安全性较低的用户,并将扫描后的结果显示出来. 1.安装John the Ripper: ...

  3. Python模块--time&datetime

    一.Python中时间的表示方式 1.时间戳  如 1552623413.043036 2.格式化的时间字符串  如 2015-12-02 3.struct_time  是一个元组 共有九个元素 二. ...

  4. DDoS 攻击与防御:从原理到实践(上)

    欢迎访问网易云社区,了解更多网易技术产品运营经验. 可怕的 DDoS 出于打击报复.敲诈勒索.政治需要等各种原因,加上攻击成本越来越低.效果特别明显等趋势,DDoS 攻击已经演变成全球性的网络安全威胁 ...

  5. Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If the number of

    class Solution { public: ListNode *reverseKGroup(ListNode *head, int k) { if (!head || !(head->ne ...

  6. ssh执行远程服务器脚本 提示php: command not found

    ssh执行远程服务器脚本 提示php: command not found 设置环境变量 一台机器作为管理机,来管理其他服务器,并通过key认证,免密码登陆的. 在管理机上通过ssh登陆到其他服务器来 ...

  7. 【SQL Server】SQL常用系统函数

    SQL常用系统函数 函数类型 函数表达式 功能 应用举例 字符串函数 SubString(表达式,起始,长度) 取子串 SubString('ABCDEFG',3,4) Right(表达式,长度) 右 ...

  8. 九度oj 题目1140:八皇后

    题目描述: 会下国际象棋的人都很清楚:皇后可以在横.竖.斜线上不限步数地吃掉其他棋子.如何将8个皇后放在棋盘上(有8 * 8个方格),使它们谁也不能被吃掉!这就是著名的八皇后问题. 对于某个满足要求的 ...

  9. iOS长按控件

    前言 网上看到一个button的长按控件效果不错,一个菱形从中间向两边增大,研究了下 原理 上图红色是控件上面放了视图,从上到下分别是view,normalLable,highlightLabel,b ...

  10. POJ——2449Remmarguts' Date(A*+SPFA)

    Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 26504   Accepted: 7203 ...