[Javascript] valueOf Object method

Returns the primitive value of the specified object.
返回指定对象的基础类型。

object.valueOf()
    Parameters : 参数
  • Array
    Returns the array instance.
  • Boolean
    The boolean value.
  • Date
    The stored time value in milliseconds midnight, January 1, 1970 UTC.
  • Function
    The function itself.
  • Number
    The numeric value.
  • Object
    The object itself. By default.
  • String
    The string value.
    Example : 例子

Continue reading

Advertisements

[Javascript] map Array method

Map is a method for javascript Array.

It calls a defined callback function on each element of an array, and returns an array that contains the results.
map函数对数组中每个元素调用一个已定义的回调方法。

yourArray.map(callbackfn[, thisArg])
    Parameters : 参数
  • yourArray
    Required. An array object. 数组(必须)
  • callbackfn
    Required. A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. 回调函数,最多可接受三个参数(必须)
  • thisArg
    Optional. An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. 关联到回调函数的一个对象(可选)
    Return : 返回值
    A new array in which each element is the callback function return value for the associated original array element. 一个重新生成的数组

Continue reading

[Javascript] hasOwnProperty

This post is just to remind me that javascript objects have a basic function hasOwnProperty which could determine whether an object has a property with a specified name.
判断对象是否包含相应的属性。

object.hasOwnProperty(proName)
    Parameters : 参数
  • object
    Required. Instance of an object. 对象的一个实例(必须)
  • proName
    Required. String value of a property name. 属性名(必须)
    Return : 返回值
  • true, if object has a property of the specified name
  • false, if it does not
    Example :
var obj = {p1:"v1", p2:"v2"}
if(obj.hasOwnProperty(p1)) {
  console.log("Yes, I have the property p1");
} else {
  console.log("Sorry, I do not have this property ");
}

If everything is ok, your console will display “Yes, I have the property p1”.

Ref. MSDN