[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)的更多相关文章
- 深入浅析JavaScript中的constructor
constructor 属性返回对创建此对象的数组函数的引用.本文给大家介绍JavaScript中的constructor ,需要的朋友参考下吧 定义和用法 constructor 属性返回对创建此对 ...
- JavaScript 系列--JavaScript一些奇淫技巧的实现方法(二)数字格式化 1234567890转1,234,567,890;argruments 对象(类数组)转换成数组
一.前言 之前写了一篇文章:JavaScript 系列--JavaScript一些奇淫技巧的实现方法(一)简短的sleep函数,获取时间戳 https://www.mwcxs.top/page/746 ...
- JavaScript 对象JavaScript 对象
JavaScript 中的所有事物都是对象:字符串.数值.数组.函数... 此外,JavaScript 允许自定义对象. 所有事物都是对象 JavaScript 提供多个内建对象,比如 String. ...
- JavaScript介绍-javaScript学习之旅(一)
javaScript简介 1.javaScript是互联网上最流行的脚本语言,这门可用于web和html,更可广泛用于服务器端,pc端,移动端. 2.javaScript脚本语言: javaScrip ...
- 网页三剑客:HTML+CSS+JavaScript 之JavaScript
JavaScript 简介 JavaScript 是互联网上最流行的脚本语言,这门语言可用于 HTML 和 web,更可广泛用于服务器.PC.笔记本电脑.平板电脑和智能手机等设备. JavaScrip ...
- javascript之 JavaScript 工具库
javascript之 JavaScript 工具库jQuery 目录: 一.查找标签和事件绑定以及操作标签的对比 二.DOM对象和jquery的转换 三.$(document).ready( ) ...
- 非侵入式JavaScript(Unobtrusive javaScript)理解
转载自 https://my.oschina.net/leegq/blog/279750 在Web的早期阶段,也就是在jQuery出现以前,在同一个文件中混杂JavaScript代码和HTML标记是非 ...
- How Javascript works (Javascript工作原理) (十一) 渲染引擎及性能优化小技巧
个人总结:读完这篇文章需要20分钟,这篇文章主要讲解了浏览器中引擎的渲染机制. DOMtree ----| |----> RenderTree CSSOMtree ----| ...
- 【JavaScript】JavaScript基础
JavaScript简介 JavaScript历史 在上世纪1995年,著名的互联网公司网景公司希望能在静态HTML页面上添加一些动态效果,于是叫Brendan Eich这哥们在两周之内设计出了Jav ...
随机推荐
- 微信小程序开发 给微信发送模板消息提示openId无效
参数我都给好了,也是post的raw方式发送请求, openId是绝对没有问题的. 但就是一直报如下错误 {"errcode":40003,"errmsg":& ...
- Windows Server 2008 R2+SQL Server 2014 R2升级到Windows Server 2016+SQL Server 2016
环境: 操作系统:Windows Server 2008 R2 数据库:SQL Server 2014 因SQL Server 2016可以无域创建AlwaysOn集群,集群只剩下单节点也不会挂掉,故 ...
- 细说unittest-2
一.unittest模块官方文档: https://docs.python.org/3/library/unittest.html 二.一张图看懂unittest: 三.Unittest主要方法属性: ...
- JAVA面向过程VS面向对象
面向过程 面向过程是一种自顶向下的编程,强调行为过程,可扩展性可维护性差. 优点: 性能比面向对象高,因为类调用时需要实例化,开销比较大,比较消耗资源. 单片机.嵌入式开发.Linux/Unix等一般 ...
- apk 解包 打包
APK应用程序的解包.修改.编辑.汉化.打包及应用 前两讲主要讲玩机的最基本的知识,集中在如何刷机.本讲是进级的内容,来谈谈与apk应用程序有关的知识,内容包括akp文件的解包.打包.反编辑.解析.汉 ...
- Knockout v3.4.0 中文版教程-12-控制文本内容和外观-html绑定
3. html绑定 目的 html绑定会使关联的DOM元素显示你参数指定的html内容. 当你的视图模型里面的值是HTML标记字符串,而你想要呈现它,这时候用html绑定特别合适. 例子 <di ...
- zoj 2388 Beat the Spread!
Beat the Spread! Time Limit: 2 Seconds Memory Limit: 65536 KB Superbowl Sunday is nearly here. ...
- Windows Server AppFabric
文章:Windows Server AppFabric简介 介绍了AppFabric强大的功能.
- redis中redis.conf配置文件
redis.conf文件配置解释 1. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 daemonize yes 2. 当Redis以守护进程方式运行时,Red ...
- ORACLE查询字段中含有空格的数据
SELECT * FROM T_NAME WHERE REGEXP_LIKE(COLNAME, '( )+'); SELECT * FROM T_NAME WHERE length(COLNAME) ...