OReilly JavaScript The Good Parts 关于Object.prototype和delete
来源:互联网 发布:央视网络电视 编辑:程序博客网 时间:2024/04/29 21:08
Every object is linked to a prototype object from which it can inherit properties.
All objects created from object literals are linked to Object.prototype,
an object that comes standard with JavaScript.
When you make a new object, you can select the object that should be its prototype.
We will add a beget method to the Object function. The beget method creates a new object
that uses an old object as its prototype.
if (typeof Object.beget !== 'function'){ Object.beget = function(o) { var F = function () {}; F.prototype = o; return new F(); };}var stooge={ name:"hebian", "no.":"001" }; var another_stooge = Object.beget(stooge);document.write(another_stooge.name);
The prototype link has no effect on updating. When we make changes to an object, the object's prototype is
not touched:
another_stooge.name = "joy";document.write(another_stooge.name);document.write(stooge.name);
The prototype relationship is a dynamic relationship. If we add a new property to a prototype, that property
will immediately be visible in all of the objects that are based on that prototype:
stooge.professional = 'actor';document.write(another_stooge.professional);document.write(stooge.professional);
The prototype link is used only in retrieval. If we try to retrieve a property value from an object, and if the
object lacks the property name, then JavaScript attempts to retrieve the property value from the prototype
object. And if that object is lacking the property, then it goes to its prototype, and so on until the process
finally bottoms out with Object.prototype.
The delete operator can be used to remove a property from an object. It will remove a property from the
object if it has one. It will not touch any of the objects in the prototype linkage.
delete another_stooge.name;document.write(another_stooge.name);
- OReilly JavaScript The Good Parts 关于Object.prototype和delete
- OReilly JavaScript The Good Parts 关于变量的使用
- OReilly JavaScript The Good Parts 关于变量Property的访问
- JavaScript: The Good Parts
- JavaScript the Good Parts 读书笔记
- 读书笔记 JavaScript:The Good Parts
- JavaScript The Good Parts 代码错误
- 读 《JavaScript: The Good Parts》 有感
- javascript the good parts Chapter 4 Functions
- JavaScript:The Good Parts学习笔记1
- 烂笔头:Javascript The Good Parts
- {Java The Good Parts}
- 《JavaScript:The Good Parts(影印版)》克罗克福特
- JavaScript : the good parts(语言精髓读书笔记)
- The R Formula Method: The Good Parts
- Javascript的prototype总结GOOD
- Learning the parts of object by NMF
- Learning the parts of object by NMF
- android的AutoCompleteTextView
- MYSQL 语句记录
- 音视频编码格式汇总
- VC6.0和VC2005项目配置详解
- 页面控件值不能回传(asp.net不同版本控件ReadOnly属性导致值回传问题)
- OReilly JavaScript The Good Parts 关于Object.prototype和delete
- 关于js的trim问题
- java IO流
- js限制input输入
- ubuntu 安装SSH mac os 连接ssh
- Java JDK 下载官方网站
- 设为首页与加入收藏的JS代码(多浏览器支持)
- Objective-C 关于 self 的用法总结
- 解决js正则匹配换行问题实现代码