// 主要是ES的API和一小部分瀏覽器的API。
// 新加入標准的API有可能是瀏覽器事實上早已實現的。
// ECMAScript目前是每年都會發布新版本(目前已經相對穩定,每年都會又增加,但是變化不會像ES6那樣大),相應的版本號如下:
// ES2015/ES6: 最大規模的一次增加,入門可看 ECMAScript 6 入門
// ES2016/ES7:
// ES2017/ES8:
全局對象(這里指的是瀏覽器環境的window對象,因為是全局環境,window通常就被省略了)
函數屬性
isNaN()(ES6在Number構造函數上也部署了)
isNaN(value)
The necessity of an isNaN function
Unlike all other possible values in JavaScript, it is not possible to rely on the equality operators (== and ===) to determine whether a value is NaN or not(isNaN()函數的目的是為了確認某個值是否是NaN), because both NaN == NaN and NaN === NaN evaluate to false. Hence, the necessity of an isNaN function.
ES6在Number上部署了isNaN()函數:
var isNaN = function(value) {
return Number.isNaN(Number(value)(相當於先轉化為了數字));
}
isFinite(testValue)(ES6在Number構造函數上部署了)
isFinite(testValue)
The global isFinite() function determines whether the passed value is a finite number(是一個有限的數). If needed, the parameter is first converted(如果參數不是數字,先轉化為數字) to a number.
eval()
eval(string)
處理URI的函數:
escape,encodeURI,encodeURIComponent有什么區別?
都是用來將字符串進行轉碼,使其在所有的電腦上都能被識別。
1、如果只是編碼字符串,不和URL有半毛錢關系,那么用escape。
2、如果你需要編碼整個URL,然后需要使用這個URL,那么用encodeURI。
3、當你需要編碼URL中的參數的時候,那么encodeURIComponent是最好方法。
encodeURIComponent() decodeURIComponent()
The encodeURIComponent() function encodes a Uniform Resource Identifier (URI) component(處理URI中的一部分) by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).
encodeURI() decodeURI()
The encodeURI() function encodes a Uniform Resource Identifier (URI)(處理整個URI) by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).
Expression and Operators(表達式和操作符)
instanceof operator
The instanceof operator tests whether an object has in its prototype chain the prototype property of a constructor.
object instanceof constructor
檢測構造器函數constructor的prototype屬性是否在object的原型鏈上
typeof
The typeof operator(typeof是一個操作符,不是函數,所以后面的()不是必須的) returns a string indicating the type of the unevaluated operand(后面的操作對象).
operand is an expression representing the object or primitive whose type is to be returned.

typeof 判斷基本類型很准確,在判斷引用類型時不准確
in operator
The in operator returns true if the specified property is in the specified object or its prototype chain(在對象或是原型鏈上是否有相應的屬性).
Object:
構造器的方法和屬性(表明構造器本身也是對象,js里面一切皆對象):
Object.prototype
The Object.prototype property represents the Object prototype object.
Object.getOwnPropertyNames()
The Object.getOwnPropertyNames() method returns an array of all properties (enumerable or not) found directly upon a given object.
返回一個對象自身上面的屬性(不包括原型鏈,包括不可枚舉屬性)組成的數組,數組元素為字符串。
Object.keys()
The Object.keys() method returns an array of a given object's own enumerable properties, in the same order as that provided by a for...in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).
返回一個對象自身上面的可枚舉屬性(不包括原型鏈,不包括不可枚舉屬性)組成的數組,數組元素為字符串。
Notes: for...in loop 遍歷自身的+原型鏈上的可枚舉屬性
Object.getOwnPropertySymbols()
The Object.getOwnPropertySymbols() method returns an array of all symbol properties found directly upon a given object.
返回一個對象自身上面的symbol屬性(不包括原型鏈)組成的數組
Object.create()
The Object.create() method creates a new object with the specified prototype object and properties.
var a = Object.create(b) // b是a的原型對象
Object.setPrototypeOf()
The Object.setPrototypeOf() method sets the prototype (i.e., the internal [[Prototype]] property) of a specified object to another object or null.
Object.setPrototypeOf(obj, prototype);
prototype是obj的原型對象
Polyfill
Using the older Object.prototype.__proto__ property, we can easily define Object.setPrototypeOf if it isn't available already:
// Only works in Chrome and FireFox, does not work in IE:
Object.setPrototypeOf = Object.setPrototypeOf || function(obj, proto) {
obj.__proto__ = proto;
return obj;
}
Object.getPrototypeOf()
The Object.getPrototypeOf() method returns the prototype (i.e. the value of the internal [[Prototype]]property) of the specified object.
Object.getPrototypeOf(obj)
obj :The object whose prototype is to be returned.
Return value:The prototype of the given object. If there are no inherited properties, null is returned.
返回obj的內部的[[prptotype]],即部分瀏覽器暴露出來的_proto_屬性對象。
Object.is()
The Object.is() method determines whether two values are the same value.
Object.assign()
Object.assign(target, ...sources)
The Object.assign() method is used to copy the values of all enumerable(可枚舉屬性,包括字符串屬性和Symbol屬性) own properties from one or more source objects to a target object. It will return the target object.
Object.getOwnPropertyDescriptor()
Object.getOwnPropertyDescriptor(obj, prop)
The Object.getOwnPropertyDescriptor() method returns a property descriptor(返回一個描述符對象) for an own property (that is, one directly present on an object and not in the object's prototype chain) of a given object.
Object.getOwnPropertyDescriptors()
Object.getOwnPropertyDescriptor(obj) //ES8
Return: An object(返回一個對象) containing all own property descriptors of an object. Might be an empty object, if there are no properties.
Object.defineProperty() Object.defineProperties(obj, props)
Object.defineProperty(obj, prop, descriptor)
The Object.defineProperty() method defines a new property directly on an object, or modifies an existing property on an object, and returns the object.
Object.preventExtensions()
Object.preventExtensions(obj)
The Object.preventExtensions() method prevents new properties from(阻止添加新的屬性,但是可以刪除之前的) ever being added to an object (i.e. prevents future extensions to the object).
Object.seal()
Object.seal(obj)
The Object.seal() method seals an object, preventing new properties from being added to it and marking all existing properties as non-configurable(阻止添加新的屬性,已有屬性的configurable設為false,即對象不可編輯). Values of present properties can still be changed as long as they are writable(但是可寫的仍可寫).
Object.freeze()
Object.freeze(obj)
The Object.freeze() method freezes an object: that is, prevents new properties from being added to it; prevents existing properties from being removed; and prevents existing properties, or their enumerability, configurability, or writability, from being changed. The method returns the object being frozen.
被凍結的對象,屬性不可添加,不可刪除屬性,屬性的特性也不可變。也就是,被凍結的對象不可改變(immutable)
To make an object constant, recursively freeze each property(遞歸的凍結對象的屬性的屬性....) which is of type object (deep freeze).
// To do so, we use this function.
function deepFreeze(obj) {
// Retrieve the property names defined on obj
var propNames = Object.getOwnPropertyNames(obj);
// Freeze properties before freezing self
propNames.forEach(function(name) {
var prop = obj[name];
// Freeze prop if it is an object
if (typeof prop == 'object' && prop !== null)
deepFreeze(prop);
});
})
// Freeze self (no-op if already frozen)
return Object.freeze(obj);
}
obj2 = {
internal: {}
};
deepFreeze(obj2);
obj2.internal.a = 'anotherValue';
obj2.internal.a; // undefined
Object.isExtensible() Object.isFrozen() Object.isSealed()
Object.isExtensible(obj)
Object.isFrozen(obj)
Object.isSealed(obj)
檢測obj是否是extensible/frozen/sealed,返回布爾值
Object.values()
Object.values(obj) // ES8
The Object.values() method returns an array(返回一個數組) of a given object's own enumerable property values(對象自身的可枚舉屬性), in the same order as that provided by a for...in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).
Object.entries()
Object.entries(obj) // ES8
The Object.entries() method returns an array of a given object's own enumerable property [key, value] pairs(對象自身可枚舉屬性的key,val組成的數組), in the same order as that provided by a for...in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).
原型對象的屬性:
Object.prototype.hasOwnProperty()
The hasOwnProperty() method returns a boolean indicating whether the object has the specified property.
返回布爾值,對象自身是否有某屬性
Object.prototype.isPrototypeOf()
The isPrototypeOf() method checks if an object exists in another object's prototype chain.
prototypeObj.isPrototypeOf(object)
檢測prototypeObj是否在object的原型鏈上
isPrototypeOf() differs from the instanceof operator. In the expression "object instanceof AFunction", the object prototype chain is checked against AFunction.prototype, not against AFunction itself.
與instanceof區別:一個是檢測對象,一個是檢測構造函數的原型對象
Object.prototype.propertyIsEnumerable()
The propertyIsEnumerable() method returns a Boolean indicating whether the specified property is enumerable.
obj.propertyIsEnumerable(prop)
Object.prototype.toString()
The toString() method returns a string representing the object.
Return value
A string representing the object.
Description
Every object has a toString() method that is automatically called(tostring()會自動被調用,當一個“字符串”被期待時) when the object is to be represented as a text value or when an object is referred to in a manner in which a string is expected. By default, the toString() method is inherited by every object descended from Object. If this method is not overridden(如果tostring方法沒有被重寫) in a custom object, toString() returns "[object type]", where type is the object type.
eg:判斷數據類型

Array
構造器的屬性(表明構造器本身也是對象,js里面一切皆對象):
Array.from()
Array.from(arrayLike[, mapFn[, thisArg]])
The Array.from() method creates a new Array instance from an array-like or iterable object(從類數組或是可遍歷的對象生成數組).
array-like objects (objects with a length property and indexed elements) or iterable objects (objects where you can get its elements, such as Map and Set).
More clearly, Array.from(obj, mapFn, thisArg) has the same result as(前后兩者的效果相同) Array.from(obj).map(mapFn, thisArg), except that it does not create an intermediate array. This is especially important for certain array subclasses, like typed arrays, since the intermediate array would necessarily have values truncated to fit into the appropriate type.
Array.isArray()
Array.isArray(obj)
The Array.isArray() determines whether the passed value is an Array(判斷是否是數組).
Polyfill
if (!Array.isArray) {
Array.isArray = function(arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
}
Array.of()
Array.of(element0[, element1[, ...[, elementN]]])
The Array.of() method creates a new Array instance with a variable number of arguments, regardless of(忽略掉參數的個數和類型) number or type of the arguments.
The difference between Array.of() and the Array constructor is in the handling of integer arguments(與Array()構造函數的區別是處理單個數字元素時): Array.of(7) creates an array with a single element, 7, whereas Array(7) creates an empty array with a length property of 7 (Note: this implies an array of 7 empty slots, not slots with actual undefined values).
Array.of(7); // [7]
Array.of(1, 2, 3); // [1, 2, 3]
Array(7); // [ , , , , , , ]
Array(1, 2, 3); // [1, 2, 3]
原型對象的屬性:
Array.prototype.toString()
The toString() method returns a string representing the specified array and its elements.
The Array object overrides the toString method of Object(重寫了Object.prototype上的toString()方法,等於.join(",")). For Array objects, the toString method joins the array and returns one string containing each array element separated by commas.
JavaScript calls the toString method automatically when an array is to be represented as a text value or when an array is referred to in a string concatenation.
Array.prototype.sort([compareFunction])
The unshift() method adds one or more elements(在數組開始添加一個或是多個元素) to the beginning of an array and returns the new length of the array.
Return value
The new length property(返回新數組的長度) of the object upon which the method was called.
Array.prototype.sort([compareFunction])
Array.prototype.sort([compareFunction])
The sort() method sorts the elements of an array in place and returns the array. The sort is not necessarily stable. The default sort order is according to string Unicode code points.
If compareFunction is not supplied, elements are sorted by converting them to strings and comparing strings(如果沒有提供compareFunction函數,則將其轉化為字符串,然后比較Unicode碼點) in Unicode code point order.
Return value
The sorted array(返回被排序過的數組).
compareFunction(a, b)的返回值小於0,則a<b;
compareFunction(a, b)的返回值大於0,則a>b;
Array.prototype.concat()
var new_array = old_array.concat(value1[, value2[, ...[, valueN]]])
拼接數組,返回新數組
Array.prototype.reduce()
Notes(應用場景):Every time you find yourself going from a list of values to one value ( reducing )(從一個列表里獲取/減少到一個值) ask yourself if you could leverage the built-in Array.prototype.reduce() function.
arr.reduce(callback, [initialValue])
callback
Function to execute on each value in the array, taking four arguments:
accumulator 累積值,不一定是累加值
The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied. (See below.)
currentValue
The current element being processed in the array.
currentIndex
The index of the current element being processed in the array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
array
The array reduce was called upon.
initialValue
Optional. Value to use as the first argument to the first call of the callback.
初始化的值,可選,如果提供,則作為回調函數的第一個參數
eg:
[0, 1, 2, 3, 4].reduce( (accumulator, currentValue, currentIndex, array) => {
return accumulator + currentValue;
}, 10);

Array.prototype.slice(begin,end)
The slice() method returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included,不包括included). The original array will not be modified.
[1,2,3,4,5].slice(1,-1) // 返回 [2,3,4]
淺復制:淺復制指的是復制的element,而不是對象本身
返回的是一個淺復制的數組,淺復制與原數組指向的是相同內存地址。
Array.prototype.splice()
array.splice(start, deleteCount, item1, item2, ...)
從start位置開始,刪除deleteCount個元素,並插入后面的元素
如果沒有插入元素,則返回undefined.
The splice() method changes the contents of an array by removing existing elements and/or adding new elements.
Return value
An array containing the deleted elements(返回被刪除的數組). If only one element is removed, an array of one element is returned. If no elements are removed, an empty array is returned.
Array.prototype.every()
Array.prototype.every(callback[, thisArg])
eg:
function isBigEnough(element, index, array) {
return element >= 10;
}
[12, 5, 8, 130, 44].every(isBigEnough); // false
[12, 54, 18, 130, 44].every(isBigEnough); // true
都為true,則為true
Array.prototype.some()
Array.prototype.some(callback[, thisArg])
eg:
function isBigEnough(element, index, array) {
return element >= 10;
}
[12, 5, 8, 130, 44].some(isBigEnough); // true
[1, 4, 5].some(isBigEnough); // false
一個為true,則為true
Array.prototype.map()
Array.prototype.map(callback[, thisArg])
The map() method creates a new array with the results of calling a provided function on every element(映射每一個元素,生成新的數組) in this array.
eg:
function isBigEnough(element, index, array) {
return element >= 10;
}
[12, 5, 8].map(isBigEnough); // [true,false,false]
Array.prototype.filter()
Array.prototype.filter(callback[, thisArg])
The filter() method creates a new array with all elements that pass the test implemented(測試函數返回true,則保留相應地元素,push進新的數組) by the provided function.
eg:
function isBigEnough(element, index, array) {
return element >= 10;
}
[12, 5, 8, 11 ].filter(isBigEnough); // [12, 11]
Array.prototype.forEach()
Array.prototype.forEach(callback[, thisArg])
The forEach() method executes a provided function once for each array element(對每一個元素依次執行函數).
eg:
var a = ['a', 'b', 'c'];
a.forEach(function(element) {
console.log(element);
});
// a
// b
// c
Array.prototype.find()
Array.prototype.find(callback[, thisArg])
The find() method returns the value of the first element in the array that satisfies the provided testing function(依次遍歷元素,如果函數返回true,則返回元素). Otherwise undefined is returned(否則返回undefined).
eg:
function isBigEnough(element, index, array) {
return element >= 10;
}
[1, 5, 8, 11, 1, 12].find(isBigEnough); // 11(返回的不是數組,返回的是元素)
Array.prototype.findIndex()
Array.prototype.findIndex(callback[, thisArg])
The findIndex() method returns the index of the first element(返回第一個函數返回true的元素的位置) in the array that satisfies the provided testing function. Otherwise -1 is returned.
eg:
function isBigEnough(element, index, array) {
return element >= 10;
}
[1, 5, 8, 11, 1, 12].findIndex(isBigEnough); // 3 (返回的元素的位置)
Array.prototype.entries()
The entries() method returns a new Array Iterator object(返回一個遍歷器對象) that contains the key/value pairs(遍歷器對象的value屬性是一個數組) for each index in the array.

Array.prototype.values()
The values() method returns a new Array Iterator object(返回一個遍歷器對象) that contains the values for each index(遍歷器對象的value就是數組的元素值) in the array.

Array.prototype.keys()
The keys() method returns a new Array Iterator that contains the keys for each index(遍歷器對象的value是數組元素的index) in the array.

Array.prototype.fill()
The fill() method fills all the elements of an array from a start index to an end index with a static value.
Array.prototype.fill(value[, start] [, end])
把數組內的所有元素轉化為一樣的
var numbers = [1, 2, 3]
numbers.fill(1);
// results in [1, 1, 1]
Array.prototype.indexOf()
Array.prototype.indexOf(searchElement[, fromIndex])
The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.
Array.prototype.includes(searchElement[, fromIndex])
// ES7 ES2016
Array.prototype.includes(searchElement[, fromIndex])
The includes() method determines whether an array includes a certain element, returning trueor false as appropriate.
包含某元素,則為true,反之則為false
If fromIndex is greater than or equal to the length of the array, false is returned.
fromIndex 默認為0,如果是負數,則從后往前搜尋。
Array.prototype.join()
Array.prototype.join([separator])
The join() method joins all elements of an array (or an array-like object) into a string.
把所有的元素拼接成字符串,seperator可選,默認值是“,”,如果數組為空,則返回空字符串,如果只有一個元素,則只返回一個元素組成的字符串。
Array.prototype.reverse()
數組位置換位
Function
構造器的屬性(表明構造器本身也是對象,js里面一切皆對象):
Function.length
The length property specifies the number of arguments(參數的個數) expected by the function.
原型對象的屬性:
Function.prototype.bind()
The bind() method creates a new function(返回一個有特定this的函數對象) that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
Function.prototype.call()
The call() method calls a function(返回的時結果,函數在特定this的情況下執行之后的結果) with a given this value and arguments provided individually.
Function.prototype.apply()
The apply() method calls a function with a given this value, and arguments provided as an array (or an array-like object).
String
構造器的屬性(表明構造器本身也是對象,js里面一切皆對象):
原型對象的屬性:
String.prototype.charAt()
str.charAt(index)
The charAt() method returns the specified character from a string(返回字符串第index位置上的字符).
If the indexyou supply is out of range, JavaScript returns an empty string.If no index is provided to .charAt(), 0 will be used as default.(index默認是0,若是index超出范圍,則返回空字符串)
String.prototype.charCodeAt()
str.charCodeAt(index)
index
An integer greater than or equal to 0 and less than the length of the string; if it is not a number(默認為0), it defaults to 0.
Return value
A number representing the UTF-16 code(返回index位置上的字符串的Unicode編碼位置) unit value of the character at the given index; NaN if index is out of range(如果index在范圍之外,則返回NaN).
String.prototype.replace()
str.replace(regexp|substr, newSubstr|function)
str里面若有第一個參數,則用第二個參數取代第一個參數。
The replace() method returns a new string with some or all matches of a patternreplaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function to be called for each match.
Return value
A new string(返回一個新的字符串,但是原來的字符串沒有變) with some or all matches of a pattern replaced by a replacement.
String.prototype.indexOf()
indexOf() method returns the index within the calling
String object of the first occurrence of the specified value, starting the search at
fromIndex. Returns -1 if the value is not found.
Return value
The index of the first occurrence of the specified value; -1 if not found.
返回特定值第一次出現的位置,如果沒有,則返回-1
String.prototype.lastIndexOf()
lastIndexOf() method returns the index within the calling
String object of the last occurrence of the specified value,
searching backwards from fromIndex(從后往前). Returns -1 if the value is not found.
String.prototype.search()
search() method executes a search for a match between a regular expression and this
Stringobject.
search vs indexOf()
search(). Otherwise,
indexOf() is going to be faster.
String.prototype.match()
obj is passed, it is implicitly converted to a
RegExp by using
new RegExp(obj). If you don't give any parameter and use the match() method directly, you will get an
Array with an empty string:[""].
match() method retrieves the matches when matching a
string against a
regular expression.
Array containing the entire match result and any parentheses-captured matched results;
null if there were no matches.
String.prototype.concat()
concat() method combines the text of one or more strings and returns a new string.
String.prototype.slice()
slice() method extracts a section of a string and returns a new string.
String.prototype.substring()
substring() method returns a subset of a
string between one index and another, or through the end of the string.
slice() vs substring() slice substring 區別
slice() works like substring() with a few different behaviors.
Syntax: string.slice(start, stop);
Syntax: string.substring(start, stop);
What they have in common:
If start equals stop: returns an empty string
If stop is omitted: extracts characters to the end of the string
If either argument is greater than the string's length, the string's length will be used instead.
Distinctions of substring():
If start > stop, then substring will swap those 2 arguments(交換兩個參數).
If either argument is negative or is NaN, it is treated as if it were 0(參數為負數或NAN,當做0).
Distinctions of slice():
If start > stop, slice() will NOT swap the 2 arguments.
If start is negative: sets char from the end of string, exactly like substr() in Firefox. This behavior is observed in both Firefox and IE.
If stop is negative: sets stop to: (string.length – 1) – Math.abs(stop) (original value).
String.prototype.substr()
substr() method returns the characters in a string beginning at the specified location through the specified number of characters.
start
Location at which to begin extracting characters. If a negative number is given(如果是負值,則從后往前), it is treated as strLength + start where strLength is the length of the string (for example, if start is -3 it is treated as strLength - 3.)
length
Optional. The number of characters to extract.
Return value
A new string containing the extracted section of the given string. If length is 0 or a negative number(如果是0或是負數,則返回新的空字符串), an empty string is returned.
String.prototype.split()
split() method splits a
String object into an array of strings by separating the string into substrings.
separator
Optional. Specifies the character(s) to use for separating the string. The
separator is treated as a
string or a regular expression(分隔符可選,是字符串或是正則表達式). If
separator is
omitted or does not occur in str, the array returned contains one element consisting of the entire string. If
separator
is an empty string,
str is converted to an array of characters
String.prototype.toLowerCase() String.prototype.toUpperCase()
str.toLowerCase()
toLowerCase() method returns the calling string value converted to lower case.
String.prototype.toLocaleLowerCase() String.prototype.toLocaleUpperCase()
toLocaleLowerCase() method returns the calling string value converted to lower case, according to any locale-specific case mappings.
String.prototype.trim() String.prototype.trimLeft() String.prototype.trimRight()
str.trim()
The trim() method removes whitespace from both ends of a string. Whitespace in this context is all the whitespace(這里的空白指的是所有的空白) characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).
Polyfill
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
}
“\uFEFF”和“\xA0”
某些軟件,在保存一個以UTF-8編碼的文件時,會在文件開始的地方插入三個不可見的字符(0xEF 0xBB 0xBF,即BOM),轉碼后是“\uFEFF”,因此我們在讀取時需要自己去掉這些字符。
“\xA0”其實就是HTML中常見的“ ”
String.prototype.padStart() String.prototype.padEnd()
str.padStart(targetLength [, padString]) // ES8
The padStart() method pads the current string with another string (repeated, if needed) so that the resulting string reaches the given length. The padding is applied from the start (left) of the current string.
用padString對str進行擴充,直到最終的長度為targetLength
Number
構造器的屬性或方法(表明構造器本身也是對象,js里面一切皆對象):
Number.isNaN()
Number.isNaN(value)
TheNumber.isNaN() method determines whether the passed value is
NaN and its type is
Number. It is a more robust version of the original, global
isNaN().
Polyfill
Number.isNaN = Number.isNaN || function(value) {
// 與window.isNaN()不同,Number.isNaN() 需要先判斷其是否是數字
return typeof value === 'number' && isNaN(value);
}
// Or
Number.isNaN = Number.isNaN || function(value) {
return value !== value;
}
Number.isFinite()
The Number.isFinite() method determines whether the passed value is a finite number.
Polyfill
Number.isFinite = Number.isFinite || function(value) {
return typeof value === 'number' && isFinite(value);
}
原型對象的屬性或方法:
Date
構造器的屬性或方法(表明構造器本身也是對象,js里面一切皆對象):
Date()
new Date();
new Date(value);
new Date(dateString);
new Date(year, month[, date[, hours[, minutes[, seconds[, milliseconds]]]]]);
- If no arguments are provided, the constructor creates a JavaScript
Dateobject for the current date(如果沒有參數,則生成當前時間的對象) and time according to system settings. - If at least two arguments are supplied, missing arguments are either set to 1 (if day is missing) or 0 for all others.
- The JavaScript date is based on a time value that is milliseconds since midnight 01 January, 1970 UTC. A day holds 86,400,000 milliseconds. The JavaScript
Dateobject range is -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC. - The JavaScript
Dateobject provides uniform behavior across platforms. The time value can be passed between systems to create a date that represents the same moment in time. - The JavaScript
Dateobject supports a number of UTC (universal) methods, as well as local time methods. UTC, also known as Greenwich Mean Time (GMT), refers to the time as set by the World Time Standard. The local time is the time known to the computer where JavaScript is executed. - Invoking JavaScript
Dateas a function (i.e., without thenewoperator(如果直接調用構造函數,沒有用new調用,則生成代表當前時間的字符串)) will return a string representing the current date and time.
Date.now()
Returns the numeric value corresponding to the current time - the number of milliseconds(當前時間的毫秒數) elapsed since 1 January 1970 00:00:00 UTC, with leap seconds ignored.
Date.prototype 原型對象的屬性或方法:
Date.prototype.getDate()
(1-31) 返回的是幾號。
Date.prototype.getDay()
(0-6)
Date.prototype.getFullYear()
(4 digits for 4-digit years)
Date.prototype.getHours()
(0-23)
Date.prototype.getMilliseconds()
Date.prototype.getMinutes()
Date.prototype.getMonth()
Date.prototype.getSeconds()
(0-59)
Date.prototype.getTime()
返回從1970.1.1 00:00 (UTC時間) 到現在的毫秒數
Date.prototype.getTimezoneOffset()
返回當前操作系統所在時區和UTC的時差,時差是分鍾。
東八區比UTC快八個小時,所以為-480.
Date.prototype.setDate()
Date.prototype.setFullYear()
Date.prototype.setHours()
Date.prototype.setMilliseconds()
Date.prototype.setMinutes()
Date.prototype.setMonth()
Date.prototype.setSeconds()
Date.prototype.setTime()
原型對象的屬性或方法:
RegExp
構造器的屬性或方法(表明構造器本身也是對象,js里面一切皆對象):
原型對象的屬性或方法:
RegExp.prototype.exec()
RegExp.prototype.exec(str)
The exec() method executes a search for a match in a specified string. Returns a result array, or null.
If you are executing a match simply to find true or false(如果你僅僅是判斷true或是false), use the RegExp.prototype.test()method or the String.prototype.search() method.
If the match succeeds, the exec() method returns an array and updates properties of the regular expression object. The returned array has the matched text as the first item(匹配出來的數組中,第一個元素是匹配的文本,后面的元素都是“括號”里面的), and then one item for each capturing parenthesis that matched containing the text that was captured.
If the match fails, the exec() method returns null.
RegExp.prototype.test()
RegExp.prototype.test(str)
The test() method executes a search for a match between a regular expression and a specified string. Returns true or false.
Math
Math is a built-in object that has properties and methods for mathematical constants and functions. Not a function object.
Description
Unlike the other global objects, Math is not a constructor(不像其它的全局對象,Math不是構造函數,是一個內置的對象). All properties and methods of Math are static. You refer to the constant pi as Math.PI and you call the sine function as Math.sin(x), where x is the method's argument. Constants are defined with the full precision of real numbers in JavaScript.
對象的屬性或方法:
Math.max([value1[, value2[, ...]]])
Math.max() function
returns the largest(返回最大值) of zero or more numbers.
