js API
1.全局對象
NAN 非數字值的特殊值
infinity 代表正無窮的數據
undefined
2.函數屬性
eval() 可計算某個字符串,并返回字符串的值
parseInt() 取整
parseFloat() 取浮點數
isNAN() 檢查參數是否是非數字
isFinite() 檢查參數是否為無窮大
3.處理URI的函數屬性
decodeURI() 可對encodeURI()函數編碼過來的URI進行解析
decodeURIComponent() 函數可對 encodeURIComponent() 函數編碼的 URI 進行解碼。
encodeURI 函數可把字符串作為 URI 進行編碼
encodeURIComponent 函數可把字符串作為 URI 組件進行編碼。
4.構造器屬性
Object 原型對象
Function 函數
Array 數組
String
Boolean
Number
Date
RegExp 正則 包含三個方法(text(),exec(),compile())
Error
EvalError
RangeError
ReferenceError
SyntaxError
TypeError
URIError
5.全局對象其他屬性
Math 數學方法
Jason
6.Object對象
構造器屬性
Object.prototype 表示對象Object的原型對象
Object.getPrototype() 返回一個obj的原型
Object.getOwnPropertyDescriptor(object, propertyname) 獲得指定對象自身屬性描述符
Object.getOwnPropertyNames() 獲得所有的屬性名,以一個數組的形式返回
Object.create(proto,[propertiesObject]) 創建一個擁有指定原型或若干原型指定原型的對象
Object.defineProperty(object, propertyname, descriptor) 1:對象 2需要定義的屬性或方法的名字 3:目標屬性所擁有的特性
Object.defineProperties(object, descriptors) 將一個屬性或多個屬性添加到對象,或修改現有屬性
Object.seal(obj)阻止修改現有屬性的特性,并阻止添加新屬性
Object.freeze(obj)阻止修改現有屬性的特性和值,并阻止添加新屬性
Object.preventExtensions(obj)阻止向對象添加新屬性
Object.isSealed(obj) 如果無法在對象中修改現有屬性的特性,且無法向對象添加新屬性,則返回true
Object.isFrozen(obj) 如果無法在對象中修改現有屬性的特性和值,且無法向對象添加新屬性,則返回true
Object.isExtensible() 返回一個值,該值指示是否可向對象添加屬性
Object.is(val1,val2) 返回一個值,該值指示兩個值時候相同
Object.keys(obj) 范湖對象可枚舉屬性和方法的名稱
原型對象屬性
proto指向該實例對象對應的原型對象 function foo(){}; var f1=new foo; console.log(f1.proyo===foo.prototype);//ture
Object.prototype 指向實力對象的原型對象
Object.prototype.constructor 返回對創建對象實例的Obj構造函數
Object.prototype.toString() 方法返回一個表示該對象的字符串
Object.prototype.toLocalString() 返回一個表示該對象的字符串.該方法主要是被本地化相關對象覆蓋
Object.protopyte.valueOf() 返回指定的原始值 好難理解
Object.prototype.hasOwnProperty(prop) 用來判斷某個對象是否含有指定屬性
Object.prototype.isPrototypeOf(obj) 用來測試一個對象是否存在另外一個對象的原型鏈上
Object.prototype.propertyIsEnumberable(prop) 返回一個布爾值,表示屬性是否是當前屬性可枚舉的布爾值
7Function對象
構造器屬性
Function.prototype 儲存function的原型對象
Function.length 形參的個數
原型對象屬性
Function.prototype.constructor
Function.prototype.toString() 返回一個表當前函數的字符串
Function.prototype.apply()
Function.prototype.call()
Function.prototype.bind() 方法會創建一個新的函數,第一個參數會作為運行時的this,之后的參數會在從傳遞的實參前傳入作為他的參數
8Array對象
構造器屬性
Array.prototype
Array.isArray
原型對象屬性
Array.prototype.constructor
Array.prototype.toString()
Array.prototype.toLocalString()
Array.prototype.concat() 合并數組
Array.prototype.join(spear) 將數組中的元素以一個字符串的形式導出,spear可為分隔符
Array.prototype.pop() 刪除數組的最后一個元素
Array.prototype.push() 添加一個或一組元素,并返回新的數組
Array.prototype.reverse() 顛倒數組中的元素 第一個會成為最后一個
Array.prototype.shift() 刪除數組中的第一個元素
Array.prototype.slice(begin,end) 淺拷貝數組里的元素,包含左邊不包含右邊
Array.prototype.sort(compareFunction) 默認元素做原地排序,compareFunction可以指定魔種排序方式
Array.prototype.splice(start,deleteCount,item1) 用新元素替換就元素,以次修改數組的內容. start開始的index,delecount持續的個數,item1替換的內容,若為空,則表示刪除 array.splice(2,0,'cat’) 把數組index=2替換為cat
Array.prototype.unshift() 在開頭添加一個或多個元素
Array.prototype.indexOf() 返回元素的索引值,不存在為-1
Array.prototype.lastIndexOf() 返回元素在數組中的最后一個索引值
Array.prototype.every() 方法測試元素是否通過指定函數的測試
function isBigEnough(element, index, array) { return (element >= 10);}
var passed = [12, 5, 8, 130, 44].every(isBigEnough);// passed is false
passed = [12, 54, 18, 130, 44].every(isBigEnough);// passed is true
Array.prototype.some() 測試數組中是否有元素通過了指定函數的檢測
Array.prototype.forEach() 數組中每個元素提供一個指定的函數
Array.prototype.map() 元素組中每一個元素調用一個方法后返回一個新的數組
Array.prototype.filter()用指定的函數測試所有元素,并創建一個包含所有通過元素的數組
Array.prototype.fill(value,start,end) 將數組摸一個區域的元素替換為value [1, 2, 3].fill(4, 1, 2) // [1, 4, 3]
Array.prototype.reduce() 函數作為一個累加器,把數組中的每個元素(自左至右)累加成一個數組
var flattened =[[0,1],[2,3],[4,5]].reduce(function(a,b){return a.concat(b),[]});
//flattened[0,1,2,3,4,5]
Array.prototype.reduceRight()
9.String對象
String.prototype
String.fromCharCode() 可接受一個unicode值,然后返回一個字符串 document.write(72,69,76,76,79) //hello
prototype屬性
String.prototype.constructor
String.prototype.toString() 將一個邏輯值轉化為字符串,并返回結果 var boo=new boolean(true) document.write(boo.toString())//true
String.prototype.valueOf() 方法返回string的原始值
String.prototype.charAt() 返回字符串中指定位置的字符
String.prototype.charCodeAt() 返回字符串的unicode值
String.prototype.concat() 將一個或多個字符串連接起來
String.prototype.indexOf(searchValue,fromindex) 指定的值在字符串中首次出現的位置.從formindex開始
String.prototype.lastIndexOf(searchValue,fromindex)指定值在字符串最后一次出現的位置.從from index開始
String.prototype.localeCompare() 比較字符串的位置
String.prototype.match(regexp) 當字符串匹配正則表達式(regexp)時,match會調用其方法
String.prototype.replace() 用一個新的字符串替換原字符串中的部分字符串
String.prototype.search(regex) 執行一個查找,看字符串對象與一個正則表達式是否契合
String.prototype.slice(begin,end) 前拷貝字符串
String.prototype.split() 把字符串分割成一個子字符串的數組 "Webkit Moz O ms Khtml".split( " " ) // ["Webkit", "Moz", "O", "ms", "Khtml”]
String.prototype.substring(startindex,endindex) 返回字符串兩個索引之間的子串
String.prototype.toLowerCase() 將字符串轉化為小寫,并返回
String.prototype.toLocalLowerCase() 字符串轉化為小寫。會根據本地化大小映射
String.prototype.toUpperCase() 轉化為大寫
String.prototype.toLocaleUpperCase()
String.prototype.trim() 刪除字符串兩端的空白符
10 Boolean對象
構造器屬性
prototype
原型對象的屬性
Boolean.prototype.constructor
Boolean.prototype.toString() 布爾對象以字符串形式返回
Boolean.prototype.valueOf() 返回原始值
11Number對象
構造器屬性
prototype
MAX_VALUE
MIN_VALUE
NaN
NEGATIVE_INFINITY 負無窮
POSITIVE_INFINITY 正無窮
原型對象的屬性
Number.prototype.constructor
Number.prototype.toString()
Number.prototype.toLocaleString()
Number.prototype.valueOf() 返回num的原始值
eg:var numObj = new Number(10);
console.log(typeof numObj); // object
var num = numObj.valueOf();
console.log(num); //
Number.prototype.toFixed() 使用定點表示法來格式化一個數
eg: var numObj = 12345.6789;
numObj.toFixed(); // 返回 "12346":進行四舍五入,不包括小數部分
numObj.toFixed(1); // 返回 "12345.7":進行四舍五入
Number.prototype.toExponential() 以指數表示法返回該數值字符串表現形式
eg: var numObj = 77.1234;
numObj.toExponential(4)); //輸出 7.7123e+1
Number.prototype.toPrecision() 以指定精度返回該數據的字符串形式
12 Math對象
值屬性
E
LN10
LN2
LOG2E
LOG10E
PI
SQRT1_2
SQRT2 2的平方根
函數屬性:
abs() 絕對值
acos()反cos
asin()
atan()
atan2() 反正切函數
ceil(x)返回一個大于或等于x的最小值
cos()
exp(x)函數返回 ex,x 表示參數
floor(x)返回一個小于或等于x的最大值
log()
max()
min()
pow(base, exponent) 函數返回基數(base)的指數(exponent)次冪
random()
round()返回一個四舍五入最接近的值
sin()
sqrt()函數返回一個平方根
tan()
13Date對象
構造器屬性
Date.prototype
Date.parse() 解析一個日期字符串,并返回為從1970到字符串的時間 Date.parse("Wed, 09 Aug 1995 00:00:00 GMT");
Date.UTC() 返回從1970到指定日期的毫秒數 Date.UTC(96, 11, 1, 0, 0, 0)
Date.now() 返回1970到當前時間的毫秒數
原型對象屬性
Date.prototype.constructor
Date.prototype.toString()
Date.prototype.toDateString()
Date.prototype.toTimeString() 差不多 格式不太相同
Date.prototype.toLocaleString()
Date.prototype.toLocaleDateString()
Date.prototype.toLocaleTimeString()
Date.prototype.valueOf() 返回對象的原始值
Date.prototype.getTime() 返回一個時間的格林尼治時間
eg: var birthday = new Date(1994, 12, 10);
birthday.getTime()
Date.prototype.getFullYear()
Date.prototype.getUTCFullYear()
Date.prototype.getMonth()
Date.prototype.getUTCMonth()
Date.prototype.getDate()
Date.prototype.getUTCDate()
Date.prototype.getDay()
Date.prototype.getUTCDay()
Date.prototype.getHours()
Date.prototype.getUTCHours()
Date.prototype.getMinutes()
Date.prototype.getUTCMinutes()
Date.prototype.getSeconds()
Date.prototype.getUTCSeconds()
Date.prototype.getMilliseconds() 根據本地時間,返回一個置頂日期對象的毫秒值
Date.prototype.getUTCMilliseconds()
Date.prototype.getTimezoneOffset()
Date.prototype.setTime()
Date.prototype.setFullYear()
Date.prototype.setUTCFullYear()
Date.prototype.setMonth()
Date.prototype.setUTCMonth()
Date.prototype.setDate()
Date.prototype.setUTCDate()
Date.prototype.setHours()
Date.prototype.setUTCHours()
Date.prototype.setMinutes()
Date.prototype.setUTCMinutes()
Date.prototype.setSeconds()
Date.prototype.setUTCSeconds()
Date.prototype.setMilliseconds()
Date.prototype.setUTCMilliseconds()
Date.prototype.toUTCString()
Date.prototype.toISOString()方法返回一個iso格式的時間 YYYY-MM-DDTHH:mm:ss.sssZ時區總是etc,后綴加一個z
Date.prototype.toJSON() 返回一個son格式的字符串
14RegExp對象
構造器屬性
RegEx.prototype
原型對象屬性
RegExp.prototype.exec() 為指定的一段字符串進行搜索匹配,返回一個數組活著null
RegExp.prototype.test() 執行一個檢索,用來查看正則表達式與指定字符串是否匹配
RegExp.prototype.toString() 返回一個表示該正則表達式的字符串
eg: foo = new RegExp("bar", "g”);
alert(foo.toString()); // 顯示 "/bar/g”
實例屬性:
source 當前正則表達式模式文本的字符串
global 是否匹配所有的選項,是一個只讀屬性,使用g標識
ignoreCase 表示忽略大小寫,只讀屬性,使用i標識
multiline 表示多行字符串被看作多行,只讀屬性,使用m標識
lastIndex