Object

本文深入探讨了JavaScript中对象的概念,包括其属性、构造、动态特性、创建方式及继承机制,强调了对象属性的使用及其与原型的关系。

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 properties
var point = { x:0, y:0 };                 // Two properties
var point2 = { x:point.x, y:point.y+1 };  // More complex values
var 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 time
var 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值