Function.prototype.apply()
git
fun.apply(thisArg, [argsArray])數組
Function.prototype.call()
:
fun.call(thisArg[, arg1[, arg2[, ...]]])app
Number.prototype.toFixed()
:
numObj.toFixed(digits) 轉換成小數模式,參數爲小數點位數this
Number.prototype.toString()
:
numObj.toString(radix) 轉換成字符串,參數爲進制數prototype
Object.prototype.hasOwnProperty()
返回true or false,對原型鏈中屬性返回falsecode
如下Object屬性爲ESC5屬性Object.keys()
返回kay組成的數組regexp
Object.freeze()
凍結一個對象,使其不可被操做對象
Object.create()
Object.create(proto [, propertiesObject ])
根據特定原型建立新對象繼承
使用Object.create實現的繼承索引
// Shape - superclass function Shape() { this.x = 0; this.y = 0; } // superclass method Shape.prototype.move = function(x, y) { this.x += x; this.y += y; console.info("Shape moved."); }; // Rectangle - subclass function Rectangle() { Shape.call(this); // call super constructor. } // subclass extends superclass Rectangle.prototype = Object.create(Shape.prototype); Rectangle.prototype.constructor = Rectangle; var rect = new Rectangle(); rect instanceof Rectangle // true. rect instanceof Shape // true. rect.move(1, 1); // Outputs, "Shape moved."
RegExp.prototype.exec()
返回結果數組或null
RegExp.prototype.test()
返回true or false
String.prototype.charAt(index)
返回特定索引的字符
String.prototype.indexOf()
str.indexOf(searchValue[, fromIndex])
返回特定字符的位置索引
"Blue Whale".indexOf("Blue"); // returns 0 "Blue Whale".indexOf("Blute"); // returns -1 "Blue Whale".indexOf("Whale", 0); // returns 5 "Blue Whale".indexOf("Whale", 5); // returns 5 "Blue Whale".indexOf("", 9); // returns 9 "Blue Whale".indexOf("", 10); // returns 10 "Blue Whale".indexOf("", 11); // returns 10
反向爲String.prototype.lastIndexOf()
String.prototype.match(regexp)
根據正則查詢,返回查詢結果數組
String.prototype.replace()
str.replace(regexp|substr, newSubStr|function[, flags]);
返回替換過的新數組
String.prototype.slice()
str.slice(beginSlice[, endSlice])
相似Array的slice,返回字符串片斷
String.prototype.split()
str.split([separator][, limit])
字符串打散爲數組
var digits = '0123456789' var a = digits.split('',5) //return ['0','1','2','3','4']
如下ESC5屬性String.prototype.trim()
裁切先後空格
整理自
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects