vauleOf是什么?

valueOf(Object.valueOf 方法)

public valueOf() : Object

返回指定对象的原始值。如果此对象没有基元值,则返回该对象。

可用性:ActionScript 1.0;Flash Player 5

返回

Object - 指定对象的原始值或对象本身。

示例

下面的示例显示某个通用对象的 valueOf()(不具有原始值)的返回值并将其与 toString() 的返回值进行比较。首先,创建一个通用对象。其次,创建一个新 Date 数据对象,将其设置为 2004 年 2 月 1 日上午 8:15。toString() 方法以可读格式返回当前时间。valueOf() 方法返回原始值,以毫秒表示。最后,创建一个包含两个简单元素的新 Array 对象。toString() 和 valueOf() 均返回相同的值:one,two:

// Create a generic object
var myObject:Object = new Object();
trace(myObject.valueOf()); // output: [object Object]
trace(myObject.toString()); // output: [object Object]

下面的示例显示内置类 Date 和 Array 的返回值,并将其与 Object.toString() 的返回值进行比较:

// Create a new Date object set to February 1, 2004, 8:15 AM
// The toString() method returns the current time in human-readable form
// The valueOf() method returns the primitive value in milliseconds
var myDate:Date = new Date(2004,01,01,8,15);
trace(myDate.toString()); // output: Sun Feb 1 08:15:00 GMT-0800 2004
trace(myDate.valueOf()); // output: 1075652100000

// Create a new Array object containing two simple elements
// In this case both toString() and valueOf() return the same value: one,two
var myArray:Array = new Array("one", "two");
trace(myArray.toString()); // output: one,two
trace(myArray.valueOf()); // output: one,two

若想了解覆盖 toString() 的自定义类的 Object.valueOf() 的返回值的示例,请参见 Object.toString() 的示例。

另请参见

toString(Object.toString 方法)


原文地址:https://www.cnblogs.com/muyoushui/p/2013708.html