js:方法3. 对象
Object.constructor###
object.constructor
a = new Array(1,2,3); // Create an object
a.constructor == Array // Evaluates to true
Object.create()###
Object.create(proto); Object.create(proto, descriptors)
// Create an object that has own properties x and y and inherits property z
var p = Object.create({z:0}, {
x: { value: 1, writable: false, enumerable:true, configurable: true},
y: { value: 2, writable: false, enumerable:true, configurable: true},
});
Object.defineProperties()###
Object.defineProperties(o, descriptors)
// Add read-only properties x and y to a newly-created object
var p = Object.defineProperties({}, {
x: { value: 0, writable: false, enumerable:true, configurable: true},
y: { value: 1, writable: false, enumerable:true, configurable: true},
});
Object.defineProperty()
Object.defineProperty(o, name, desc)
function constant(o, n, v) { // Define a constant o.n with value v
Object.defineProperty(o, n, { value: v, writable: false
enumerable: true, configurable:false});
}
Object.getOwnPropertyDescriptor()
Object.getOwnPropertyDescriptor(o, name)
The descriptor for a data property looks like this:
{
value: /* any JavaScript value */,
writable: /* true or false */,
enumerable: /* true or false */,
configurable: /* true or false */
}
The descriptor for an accessor property looks like this:
{
get: /* function or undefined: replaces the property value */,
set: /* function or undefined: replaces the writable attribute */,
enumerable: /* true or false */,
configurable: /* true or false */
}
Object.getOwnPropertyNames()
Object.getOwnPropertyNames(o)
Object.getOwnPropertyNames([]) // => ["length"]: "length" is non-enumerable
Object.getPrototypeOf()
Object.getPrototypeOf(o)
var p = {}; // An ordinary object
Object.getPrototypeOf(p) // => Object.prototype
var o = Object.create(p) // An object that inherits from p
Object.getPrototypeOf(o) // => p
Object.hasOwnProperty()###
object.hasOwnProperty(propname)
var o = new Object(); // Create an object
o.x = 3.14; // Define a noninherited local property
o.hasOwnProperty("x"); // Returns true: x is a local property of o
o.hasOwnProperty("y"); // Returns false: o doesn't have a property y
o.hasOwnProperty("toString"); // Returns false: toString property is inherited
Object.isPrototypeOf()###
object.isPrototypeOf(o)
var o = new Object(); // Create an object
Object.prototype.isPrototypeOf(o) // true: o is an object
Function.prototype.isPrototypeOf(o.toString); // true: toString is a function
Array.prototype.isPrototypeOf([1,2,3]); // true: [1,2,3] is an array
// Here is a way to perform a similar test
(o.constructor == Object); // true: o was created with Object() constructor
(o.toString.constructor == Function); // true: o.toString is a function
// Prototype objects themselves have prototypes. The following call
// returns true, showing that function objects inherit properties
// from Function.prototype and also from Object.prototype.
Object.prototype.isPrototypeOf(Function.prototype);
Object.keys()###
Object.keys(o)
Object.keys({x:1, y:2}) // => ["x", "y"]
Object.propertyIsEnumerable()###
object.propertyIsEnumerable(propname)
var o = new Object(); // Create an object
o.x = 3.14; // Define a property
o.propertyIsEnumerable("x"); // true: property x is local and enumerable
o.propertyIsEnumerable("y"); // false: o doesn't have a property y
o.propertyIsEnumerable("toString"); // false: toString property is inherited
Object.prototype.propertyIsEnumerable("toString"); // false: nonenumerable
js:方法3. 对象的更多相关文章
- (转)Silverlight调用的JS方法返回对象数组的处理方法
最近在做Silverlight应用,需要用Silverlight调用页面中Javascript方法.这 个JS方法返回一个对象数组给Silverlight.对于这个对象数组怎么在Silverlight ...
- js方法在对象中的状态
在C#中,只有对象的字段存储在堆中,而方法则存储在一个方法表中.当实例化多个对象时,为字段分配了内存空间,而方法都指向一个方法表中的同一个方法. 如 而在JS中,字段和方法都属于值类型,都存储在堆中. ...
- js方法传入对象;js方法传入方法;js方法回调 callback
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JS中的对象和方法简单剖析
众所周知,在js中对象就是精髓,不理解对象就是不理解js. 那么什么事js中的对象呢? 在js中,几乎一切皆对象: Boolean ,String,Number可以是对象(或者说原生数据被认作对象): ...
- 关于js函数,方法,对象实例的一些说明
朋友们大家好,好久没有更新文章了,最近正好有空就想着写点什么吧,加上这段时间总是能听到一些朋友们问关于js函数,方法,对象实例到底有什么区别这个问题,所以今天就献丑来简单说明一些吧! 其实这些主要都是 ...
- js对数组对象的操作以及方法的使用
js对数组对象的操作以及方法的使用 如何声明创建一个数组对象: var arr = new Array(); 或者 var arr = []; 如何移除所有数组中数据? arrayJson.dataL ...
- js之global 对象 方法
global 作为js的全局对象,但其是无法直接访问的,但是在浏览器中浏览器是将这个对象当做是window对象的一部分,即Date 等Global的属性使用window.Date 可访问到 1.url ...
- 拼接的html的onclick事件中无法传递对象给js方法的处理办法
如下: 拼接的html: " onclick=\"valDocName2('"+JSON.stringify(doc).replace(new RegExp(" ...
- JS类、对象、方法、prototype、_proto_
案例代码: function People(name) { //对象属性 this.name = name; //对象方法 this.Introduce = function() { alert(&q ...
随机推荐
- IOS - 本地数据持久化
转:相对复杂的App仅靠内存的数据肯定无法满足,数据写磁盘作持久化存储是几乎每个客户端软件都需要做的.简单如“是否第一次打开”的BOOL值,大 到游戏的进度和状态等数据,都需要进行本地持久化存储.这些 ...
- ios waxpatch lua语法
Wax Lua 使用方法 说一下 Wax 的特点,它支持你在脚本里使用任何 OC 的类,同样也支持你创建一个类. 使用一个类时你会这样使用: 1 2 NSString -- Returns the N ...
- 【转】C++多态性
----转自http://blog.csdn.net/hackbuteer1/article/details/7475622 C++编程语言是一款应用广泛,支持多种程序设计的计算机编程语言.我们今天就 ...
- iPhone:4.7 5.5 4 3.5 对应的各个设备屏幕尺寸对应的像素及App上线信息
Shared App Information You can access these properties from the App Details page in the App Informat ...
- NYOJ题目75日期计算
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr4AAAInCAIAAADxjM2pAAAgAElEQVR4nO3dPVLjStsG4G8T5CyE2A
- 整理 iOS 9 适配中出现的坑(图文)(转)
作者:董铂然 本文主要是说一些iOS9适配中出现的坑,如果只是要单纯的了解iOS9新特性可以看瞄神的开发者所需要知道的 iOS 9 SDK 新特性.9月17日凌晨,苹果给用户推送了iOS9正式版,随着 ...
- MVC – 14.ajax异步请求
14.1.配置文件 14.2.AjaxHelper – 异步链接按钮 14.3.AjaxHelper – 异步表单 AjaxOptions常见属性: 14.4.AjaxOptions对象生成[对应]触 ...
- Java 解析XML的几种方法
XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的方便. XML在不同的语言里解析方式都是一样的,只不过实现的语法不同而已. 基本的解析方式 ...
- C# 设计模式 提高可维护性的几点原则
为了提高软件的可维护性,应该遵循以下几点原则: 1.“开放--封闭”原则(OCP) 一个软件实体应该对扩展开放,对修改封闭. 2.里氏代换原则(LSP) 子类型必须能替换她们的基类型,反过来则不成立. ...
- Newtonsoft.Json(Json.Net)学习笔记-高级使用(转)
1.忽略某些属性 2.默认值的处理 3.空值的处理 4.支持非公共成员 5.日期处理 6.自定义序列化的字段名称 7.动态决定属性是否序列化 8.枚举值的自定义格式化问题 9.自定义类型转换 10.全 ...