博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Object
阅读量:6316 次
发布时间:2019-06-22

本文共 2483 字,大约阅读时间需要 8 分钟。

An object is an unordered collection of properties, each of witch has a name and value. 

An object is more than a simple string-to-value map, in addition to maintaining its own set of properties.

a JavaScript object alse inherits the properties of another object, know as its "prototype", and this "prototypal inheritance" is a key feature of JavaScript

JavaScript objects are dynamic--properties can usually be added and deleted.

Object can be created with object literals, with the new keyword, and with  the Object.create() function.

var empty = {};                           // An object with no propertiesvar point = { x:0, y:0 };                 // Two propertiesvar point2 = { x:point.x, y:point.y+1 };  // More complex valuesvar book = {                          "main title": "JavaScript",           // Property names include spaces,    'sub-title': "The Definitive Guide",  // and hyphens, so use string literals    "for": "all audiences",               // for is a reserved word, so quote    author: {                             // The value of this property is        firstname: "David",               // itself an object.  Note that        surname: "Flanagan"               // these property names are unquoted.    }};
var o = new Object();     // Create an empty object: same as {}.var a = new Array();      // Create an empty array: same as [].var d = new Date();       // Create a Date object representing the current timevar r = new RegExp("js"); // Create a RegExp object for pattern matching.

Every Javascript object has a secend object associated with it. This second object is known as a prototype, and the first object inherits properties from the prototype.

All objects created by object literals have the same prototype object, and we can refer to this object like this:

Object.prototype.

Object created using the new keyword and a constructor invocation use the value of the prototype property of the constructor functions  as their prototype.

So the object created by new Object() inherit from Object.prototype just as the object created by {} dose.

Object.prototype is one of the rare object that has no prototype: it does not inherit any properties. 

All of the built-in constructors have a prototype that inherit from Object.prototype.

Object.create() creates a new object, using its first argument as the prototype of the object

var o1 = Object.create({x:1, y:2});       // o1 inherits properties x and y.

 

转载于:https://www.cnblogs.com/woodynd/p/4015898.html

你可能感兴趣的文章
GO数据库
查看>>
JavaWeb中filter的详解及应用案例
查看>>
火狐firefox进行post提交测试
查看>>
简单分布式爬虫
查看>>
字节流和字符流的read方法
查看>>
LeetCode - 8. String to Integer (atoi)
查看>>
关于接口是值类型还是引用类型的猜测
查看>>
《程序员代码面试指南》第三章 二叉树问题 遍历二叉树的神级方法 morris
查看>>
CSU 1803 2016
查看>>
第九章 原型模式
查看>>
[Java] 在JSP中读取POST的JSON数据
查看>>
含有截止显示时间的移动端弹框信息提示插件
查看>>
导出Excel之判断电脑中office的版本
查看>>
众数问题(为什么只能输入一组数据,不能输入m组数据)
查看>>
布局适配
查看>>
抽屉之Tornado实战(7)--form表单验证
查看>>
机器学习笔记(Washington University)- Regression Specialization-week five
查看>>
ubuntu下配置nginx+php
查看>>
开发环境介绍及音效选取方案
查看>>
调用Windows API实现GBK和UTF-8的相互转换
查看>>