分享JavaScript?類型判斷的幾種方法
一、JavaScript 基本類型
首先介紹一下JavaScript中的八大基本類型
1、原始數(shù)據(jù)類型
除對(duì)象類型(object)以外的其它任何類型定義的不可變的值(值本身無(wú)法被改變)。例如(與 C 語(yǔ)言不同),JavaScript 中字符串是不可變的(譯注:如,JavaScript 中對(duì)字符串的操作一定返回了一個(gè)新字符串,原始字符串并沒(méi)有被改變)。我們稱這些類型的值為“原始值”。 —— MDN
(1)布爾類型(Boolean)
布爾表示一個(gè)邏輯實(shí)體,可以有兩個(gè)值:true
和false
、
(2)Null類型
- Null 類型只有一個(gè)值:
null
- 值 null 是一個(gè)字面量,是表示缺少的標(biāo)識(shí),只是變量未指向任何對(duì)象。
- 注意:可以把 null 作為尚未創(chuàng)建的對(duì)象,但是 null 并非對(duì)象。
(3)Undefined類型
- undefined:一個(gè)聲明未定義的變量的初始值,或沒(méi)有實(shí)際參數(shù)的形式參數(shù)。
undefined
是全局對(duì)象的一個(gè)屬性。也就是說(shuō),它是全局作用域的一個(gè)變量。undefined
的最初值就是原始數(shù)據(jù)類型undefined。
console.log(undefined in window) // true let a; console.log(a) // undefined
- 一個(gè)函數(shù)如果沒(méi)有使用return語(yǔ)句指定返回值,就會(huì)返回一個(gè)undefined值。
function f() { } console.log(f()) // undefined
(4)數(shù)字類型(Number)
- 數(shù)字類型是一種基于 IEEE 754 標(biāo)準(zhǔn)的雙精度 64 位二進(jìn)制格式的值,能表示整數(shù)和浮點(diǎn)值
- 值的范圍: Number.MIN_VALUE(5e-324)— Number.MAX_VALUE(1.7976931348623157e+308)
- 如果某個(gè)正值大于 Number.MAX_VALUE,則表示為
Infinity
(或者+Infinity)- 如果某個(gè)負(fù)值小于 -Number.MAX_VALUE則表示為
-Infinity
- 如果某個(gè)正值小于 Number.MIN_VALUE,則表示為0(或者+0)
- 如果某個(gè)負(fù)值大于 -Number.MIN_VALUE則表示為-0
- 如果某個(gè)負(fù)值小于 -Number.MAX_VALUE則表示為
// 注意:Number.MIN_VALUE(5e-324)— Number.MAX_VALUE(1.7976931348623157e+308) 是可以表示的正值范圍 console.log(Number.MIN_VALUE); // 5e-324 console.log(Number.MAX_VALUE); // 1.7976931348623157e+308 console.log(1e310); // Infinity console.log(-1e310); // -Infinity console.log(1e-330); // 0 console.log(-1e-330); // 0
NaN
(非數(shù)值,Not-a-Number)。
not-a-number:
NaN
是一個(gè)全局對(duì)象的屬性。NaN
屬性的初始值就是 NaN,和Number.NaN
的值一樣。
- 數(shù)字類型中只有一個(gè)整數(shù)有兩種表示方法:0可表示為-0和+0(0是+0的簡(jiǎn)寫)。
(5)BigInt
- BigInt 類型是 JavaScript 中的一個(gè)基礎(chǔ)的數(shù)值類型,可以表示任意精度的整數(shù)。使用 BigInt,您可以安全地存儲(chǔ)和操作大整數(shù),甚至可以超過(guò)數(shù)字類型的安全整數(shù)限制。(BigInt 與 Number 的主要區(qū)別在于,BigInt能在內(nèi)存中精確表示超過(guò)安全限制的整數(shù))
// 數(shù)字類型安全整數(shù)限制 console.log(Number.MIN_SAFE_INTEGER) // -9007199254740991 console.log(Number.MAX_SAFE_INTEGER) // 9007199254740991
- BigInt 是通過(guò)在整數(shù)末尾附加字母
n
或調(diào)用構(gòu)造函數(shù)來(lái)創(chuàng)建的。
// 構(gòu)造函數(shù)創(chuàng)建 // BigInt() 不與 new 運(yùn)算符一起使用。 let a = BigInt(1); // 末尾附加字母n創(chuàng)建 let b = 1n; console.log(a) // 1n console.log(b) // 2n
BigInt
不能與數(shù)字相互運(yùn)算。否則,將拋出TypeError
。
console.log(1 + 1n); //Uncaught TypeError: Cannot mix BigInt and other types, use explicit conversions
(6)字符串類型(String)
JavaScript 的字符串類型用于表示文本數(shù)據(jù)。它是一組 16 位的無(wú)符號(hào)整數(shù)值的“元素”。在字符串中的每個(gè)元素占據(jù)了字符串的位置。第一個(gè)元素的索引為0
,下一個(gè)是索引1
,依此類推。字符串的長(zhǎng)度是它的元素的數(shù)量。
(7)符號(hào)類型(Symbols)
- 符號(hào)(Symbols)類型是唯一且不可修改的原始值,該類型的性質(zhì)在于這個(gè)類型的值可以用來(lái)創(chuàng)建匿名的對(duì)象屬性,可以用來(lái)作為對(duì)象的鍵(key)
- 可以通過(guò)調(diào)用函數(shù) Symbol() 來(lái)創(chuàng)建 Symbol 數(shù)據(jù)類型實(shí)例。
- 當(dāng)一個(gè) symbol 類型的值在屬性賦值語(yǔ)句中被用作標(biāo)識(shí)符,該屬性(像這個(gè) symbol 一樣)是匿名的;并且是不可枚舉的。因?yàn)檫@個(gè)屬性是不可枚舉的,它不會(huì)在循環(huán)結(jié)構(gòu) “
for( ... in ...)
” 中作為成員出現(xiàn),也因?yàn)檫@個(gè)屬性是匿名的,它同樣不會(huì)出現(xiàn)在 “Object.getOwnPropertyNames()
” 的返回?cái)?shù)組里。這個(gè)屬性可以通過(guò)創(chuàng)建時(shí)的原始 symbol 值訪問(wèn)到,或者通過(guò)遍歷 “Object.getOwnPropertySymbols()
” 返回的數(shù)組。在之前的代碼示例中,通過(guò)保存在變量myPrivateMethod
的值可以訪問(wèn)到對(duì)象屬性。 - symbol 值提供了一種自定義類可以創(chuàng)建私有成員的方式,并維護(hù)一個(gè)僅適用于該類的 symbol 注冊(cè)表。 自定義類可以使用 symbol 值來(lái)創(chuàng)建“自有”屬性,這些屬性避免了不必要的被偶然發(fā)現(xiàn)帶來(lái)的影響。 在類定義中,動(dòng)態(tài)創(chuàng)建的 symbol 值將保存到作用域變量中,該變量只能在類定義中私有地使用。
2、引用數(shù)據(jù)類型
對(duì)象類型(Object)
在計(jì)算機(jī)科學(xué)中, 對(duì)象(object)是指內(nèi)存中的可以被標(biāo)識(shí)符引用的一塊區(qū)域。
在 JavaScript 中,對(duì)象可以被看作是一組屬性的集合。用對(duì)象字面量語(yǔ)法來(lái)定義一個(gè)對(duì)象時(shí),會(huì)自動(dòng)初始化一組屬性。而后,這些屬性還可以被添加和移除。
- 屬性的值可以是任意類型,包括其它對(duì)象。
- 屬性使用鍵(key)來(lái)標(biāo)識(shí),它的鍵值可以是一個(gè)字符串或者符號(hào)值(Symbol)。
對(duì)象擁有兩種屬性:
a、數(shù)據(jù)屬性
b、訪問(wèn)器屬性
JavaScript中提供了很多內(nèi)置對(duì)象,可參考MDN官方文檔。
3、兩種數(shù)據(jù)類型的存儲(chǔ)方式
(1)原始數(shù)據(jù)類型:
基礎(chǔ)類型存儲(chǔ)在棧內(nèi)存,被引用或拷貝時(shí),會(huì)創(chuàng)建一個(gè)完全相等的變量;占據(jù)空間小、大小固定,屬于被頻繁使用數(shù)據(jù),所以放入棧中存儲(chǔ)。
(2)引用數(shù)據(jù)類型:
引用類型存儲(chǔ)在堆內(nèi)存,存儲(chǔ)的是地址,多個(gè)引用指向同一個(gè)地址,這里會(huì)涉及一個(gè)“共享”的概念;占據(jù)空間大、大小不固定。引用數(shù)據(jù)類型在棧中存儲(chǔ)了指針,該指針指向堆中該實(shí)體的起始地址。當(dāng)解釋器尋找引用值時(shí),會(huì)首先檢索其在棧中的地址,取得地址后從堆中獲得實(shí)體。
所以,在 JavaScript 中,原始類型的賦值會(huì)完整復(fù)制變量值,而引用類型的賦值是復(fù)制引用地址。
二、Javascript 數(shù)據(jù)類型判斷的幾種方法
1、typeof
typeof
操作符返回一個(gè)字符串,表示未經(jīng)計(jì)算的操作數(shù)的類型。
語(yǔ)法:
// operand:一個(gè)表示對(duì)象或原始值的表達(dá)式,其類型將被返回 typeof operand typeof(operand)
返回值:
"undefined" "object" "boolean" "number" "bigint" "string" "symbol" "function" "object"
(1)不同數(shù)據(jù)類型的 typeof 值
// 歷史遺留問(wèn)題 console.log(typeof null); // object // Undefined 類型typeof值為 undefined console.log(typeof undefined); // undefined // 未定義的變量 typeof值也為 undefined console.log(typeof a); // undefined // 非數(shù)值 console.log(typeof NaN); // number // 無(wú)窮大 console.log(typeof Infinity); // number // 除 Null 和 Undefined 之外的原始數(shù)據(jù)類型 typeof 值都是對(duì)應(yīng)的類型 console.log(typeof true); // boolean console.log(typeof 2); // number console.log(typeof 2n); // bigint console.log(typeof BigInt(1)); // bigint console.log(typeof 'str'); // string console.log(typeof Symbol(1)); // symbol console.log(typeof Boolean(true)); // boolean console.log(typeof Number(1)); // number console.log(typeof String('str')); // string // 基本包裝類型 console.log(typeof new Boolean(true)); // object console.log(typeof new Number(1)); // object console.log(typeof new String('str')); // object // 字面量 console.log(typeof {}); // object console.log(typeof []); // object console.log(typeof /1/); // object // 除了 Function 對(duì)象實(shí)例, typeof值都是 object console.log(typeof new Object()); // object console.log(typeof new Array()); // object console.log(typeof new Map()); // object console.log(typeof new Set()); // object console.log(typeof new Date()); // object console.log(typeof new RegExp()); // object console.log(typeof Math); // object // Function 對(duì)象實(shí)例, typeof值為 function console.log(typeof new Function()); // function console.log(typeof Function); // function console.log(typeof Array); // function console.log(typeof Set); // function console.log(typeof Date); // function console.log(typeof RegExp); // function console.log(typeof Object); // function
(2) typeof null === 'object' 的原因
“typeof null”錯(cuò)誤是 JavaScript 第一版的遺留物。在這個(gè)版本中,值存儲(chǔ)在 32 位單元中,由一個(gè)小型標(biāo)簽(1-3 位)和值的實(shí)際數(shù)據(jù)組成。類型標(biāo)簽存儲(chǔ)在單元的低位中。
其中有五個(gè):
- 000:對(duì)象。數(shù)據(jù)是對(duì)對(duì)象的引用。
- 1:整數(shù)。數(shù)據(jù)是一個(gè) 31 位有符號(hào)整數(shù)。
- 010:雙倍。數(shù)據(jù)是對(duì)雙浮點(diǎn)數(shù)的引用。
- 100:字符串。數(shù)據(jù)是對(duì)字符串的引用。
- 110:布爾值。數(shù)據(jù)是布爾值。
也就是說(shuō),最低位是任一位,那么類型標(biāo)簽只有一位長(zhǎng)。或者為零,則類型標(biāo)簽的長(zhǎng)度為三位,為四種類型提供兩個(gè)額外的位。
有兩個(gè)值是特殊的:
- undefined ( JSVAL_VOID ) 是整數(shù) -2 30(整數(shù)范圍之外的數(shù)字)。
- null ( JSVAL_NULL ) 是機(jī)器碼 NULL 指針?;蛘撸阂粋€(gè)對(duì)象類型標(biāo)簽加上一個(gè)為零的引用。(表示為全0)
所以 typeof 認(rèn)為 null 是一個(gè) object
(3)對(duì)象類型 typeof 返回值的理解
針對(duì)對(duì)象類型,個(gè)人理解 的是:
- 如果是Function對(duì)象, 那么返回值則是function
- 如果是其他任何普通對(duì)象, 那么返回值則是object,
(4)關(guān)于 typeof Boolean(true) 和 typeof new Boolean(true)不同的原因
// 簡(jiǎn)單調(diào)用Boolean() 函數(shù) console.log(Boolean(true)); // true // 創(chuàng)建一個(gè)Boolean對(duì)象 console.log(new Boolean(true)); // Boolean {true}
Boolean(true) 的返回值就是Boolean類型的數(shù)據(jù),newBoolean(true)返回的是一個(gè)Boolean對(duì)象。
(5)總結(jié)
- typeof 可以判斷除 null 之外所有原始數(shù)據(jù)類型
- typeof 在判斷實(shí)例類型時(shí),根據(jù)實(shí)例的構(gòu)造函數(shù)返回 object 或 function
- typeof null === 'object' 是一個(gè)歷史遺留問(wèn)題,無(wú)法修改。
- typeof NaN === 'number'
2、instanceof
instanceof
運(yùn)算符用于檢測(cè)構(gòu)造函數(shù)的 prototype
屬性是否出現(xiàn)在某個(gè)實(shí)例對(duì)象的原型鏈上
語(yǔ)法:
// object:某個(gè)實(shí)例對(duì)象 // constructor:某個(gè)構(gòu)造函數(shù) object instanceof constructor
(1)相關(guān)例子
// instanceof 右邊是一個(gè)構(gòu)造函數(shù),所以u(píng)ndefined 和 null 不能使用instanceof,下面兩條語(yǔ)句執(zhí)行會(huì)報(bào)錯(cuò) // console.log(undefined instanceof Undefined); // console.log(null instanceof Null); // 對(duì)于原始數(shù)據(jù)類型無(wú)法檢測(cè) console.log(2 instanceof Number); // false console.log(1n instanceof BigInt); // false console.log(true instanceof Boolean); // false console.log('str' instanceof String); // false console.log(Symbol(1) instanceof Symbol); // false // 可以檢測(cè)內(nèi)置對(duì)象類型 console.log([] instanceof Array); // true console.log(function(){} instanceof Function); // true console.log({} instanceof Object); // true console.log(/1/ instanceof RegExp); // true // 所有函數(shù)對(duì)象實(shí)例原型鏈上都存在Function console.log(Array instanceof Function); // true console.log(Set instanceof Function); // true console.log(Map instanceof Function); // true console.log(Date instanceof Function); // true console.log(RegExp instanceof Function); // true console.log(Function instanceof Function); // true console.log(Object instanceof Function); // true // Object 是所有實(shí)例對(duì)象原型鏈的盡頭 console.log(Array instanceof Object); // true console.log(Set instanceof Object); // true console.log(Map instanceof Object); // true console.log(Date instanceof Object); // true console.log(RegExp instanceof Object); // true console.log(Function instanceof Object); // true console.log(Object instanceof Object); // true function foo() {} // foo 是 Function的一個(gè)實(shí)例 console.log(foo instanceof Object); // true console.log(foo instanceof Function); // true // new foo() 是 foo 的一個(gè)實(shí)例 console.log(new foo() instanceof foo); // true console.log(new foo() instanceof Object); // true console.log(new foo() instanceof Function); // false // foo() 返回的是undefined console.log(foo() instanceof Object); // false console.log(foo() instanceof Function); // false
(2) 當(dāng)構(gòu)造函數(shù)的proptotype發(fā)生改變時(shí),instanceof 結(jié)果可能會(huì)出錯(cuò)
function foo() {} let f = new foo(); console.log(f instanceof foo) // true // foo 原型發(fā)生改變 foo.prototype = Array.prototype; console.log(f instanceof foo); // false
(3)手動(dòng)實(shí)現(xiàn) instanceof
function myInstanceof(left, right) { // 獲得構(gòu)造函數(shù)的原型 let prototype = right.prototype // 獲得對(duì)象的原型 left = left.__proto__ // 判斷對(duì)象的類型是否等于類型的原型 while (true) { // 原型鏈的盡頭是 null,說(shuō)明實(shí)例對(duì)象的原型鏈遍歷結(jié)束 if (left === null) return false if (prototype === left) return true left = left.__proto__ } }
上述手動(dòng)實(shí)現(xiàn)只是實(shí)現(xiàn)了基本功能,但與原生instanceof仍然存在差別,例如:
- 未對(duì) right 進(jìn)行錯(cuò)誤處理
// 檢驗(yàn)right 是否是一個(gè)對(duì)象(Object) if (right is not Object){ throw new TypeError(" Uncaught TypeError: Right-hand side of 'instanceof' is not Object") } // 檢驗(yàn) right 是否可被調(diào)用 if (right is not callable) { throw new TypeError(" Uncaught TypeError: Right-hand side of 'instanceof' is not callable") }
- myInstanceof('str', String) === true
console.log(_instanceof('str', String)) // true
有關(guān)instanceof 原理,可繼續(xù)深入了解原型鏈相關(guān)知識(shí)點(diǎn)。
(4)總結(jié)
- instanceof 不能判斷原始數(shù)據(jù)類型
- instanceof 能夠判斷引用數(shù)據(jù)類型,但由于是查找原型鏈,所以不能很精準(zhǔn)指出數(shù)據(jù)類型。
例如:
console.log([] instanceof Array); // true console.log([] instanceof Object); // true
- 當(dāng)構(gòu)造函數(shù)的 prototype 發(fā)生改變時(shí),會(huì)導(dǎo)致 instanceof 結(jié)果發(fā)生改變,詳見(2)
所以 instanceof 用于判斷數(shù)據(jù)類型也存在弊端。
3、構(gòu)造函數(shù)(constructor)
(1)相關(guān)例子
// null 和 undefined 沒(méi)有構(gòu)造函數(shù) onsole.log(null.constructor) // TypeError onsole.log(undefined.constructor) // TypeError // 原始數(shù)據(jù)類型 console.log((2).constructor === Number); // true console.log((2n).constructor === BigInt); // true console.log((true).constructor === Boolean); // true console.log(('str').constructor === String); // true console.log(Symbol(1).constructor === Symbol); // true // 字面量 console.log(([]).constructor === Array); // true console.log((/1/).constructor === RegExp); // true console.log((function() {}).constructor === Function); // true console.log(({}).constructor === Object); // true // JavaScript中的內(nèi)置函數(shù)對(duì)象的構(gòu)造函數(shù)為 Function console.log(Array.constructor === Function); // true console.log(String.constructor === Function); // true console.log(Function.constructor === Function); // true console.log(Object.constructor === Function); // true // JavaScript中的內(nèi)置普通對(duì)象的構(gòu)造函數(shù)為 Object console.log(Math.constructor === Object); // true console.log(JSON.constructor === Object); // true console.log(Atomics.constructor === Object); // true console.log(Intl.constructor === Object); // true console.log(Reflect.constructor === Object); // true console.log(WebAssembly.constructor === Object); // true
(2)如果創(chuàng)建一個(gè)對(duì)象前修改構(gòu)造函數(shù)的原型,會(huì)導(dǎo)致constructor不可靠
function Fn(){}; Fn.prototype=new Array(); var f=new Fn(); console.log(f.constructor===Fn); // false console.log(f.constructor===Array); // true
(3)總結(jié)
- 通過(guò)構(gòu)造函數(shù) constructor 能夠準(zhǔn)確判斷出數(shù)據(jù)類型,但 null 和 undefined 沒(méi)有構(gòu)造函數(shù),無(wú)法判斷
- 內(nèi)置函數(shù)對(duì)象的構(gòu)造函數(shù)都是 Function,例如 Array、Map等;內(nèi)置普通對(duì)象的構(gòu)造函數(shù)是Object,例如:JSON、Atomic、Intl、Reflect、WebAssembly 等
- 在創(chuàng)建實(shí)例前修改實(shí)例的原型,會(huì)導(dǎo)致constructor不可靠
所以 constructor 判斷數(shù)據(jù)類型也存在弊端。
4、Object.prototype.toString.call()
(1)Object.prototype.toString()
每個(gè)對(duì)象都有一個(gè)
toString()
方法,當(dāng)該對(duì)象被表示為一個(gè)文本值時(shí),或者一個(gè)對(duì)象以預(yù)期的字符串方式引用時(shí)自動(dòng)調(diào)用。默認(rèn)情況下,toString()
方法被每個(gè)Object
對(duì)象繼承。如果此方法在自定義對(duì)象中未被覆蓋,toString()
返回 "[object type]" ,其中type
是對(duì)象的類型 —— MDN
(2) Object.prototype.toString.call() 實(shí)例
// 原始數(shù)據(jù)類型 console.log(Object.prototype.toString.call(undefined)) // [object Undefined] console.log(Object.prototype.toString.call(null)) // [object Null] console.log(Object.prototype.toString.call(1)) // [object Number] console.log(Object.prototype.toString.call(1n)) // [object BigInt] console.log(Object.prototype.toString.call(true)) // [object Boolean] console.log(Object.prototype.toString.call('str')) // [object String] console.log(Object.prototype.toString.call(Symbol(1))) // [object Symbol] // 字面量 console.log(Object.prototype.toString.call({})) // [object object] console.log(Object.prototype.toString.call([])) // [object Array] console.log(Object.prototype.toString.call(/1/)) // [object RegExp] console.log(Object.prototype.toString.call(NaN)) // [object Number] console.log(Object.prototype.toString.call(Infinity)) // [object Number] console.log(Object.prototype.toString.call(globalThis)) // [object Window] // 內(nèi)置函數(shù)對(duì)象實(shí)例 console.log(Object.prototype.toString.call(new Array())) // [object Array] console.log(Object.prototype.toString.call(new Map())) // [object Map] console.log(Object.prototype.toString.call(new Set())) // [object Set] console.log(Object.prototype.toString.call(new Date())) // [object Date] console.log(Object.prototype.toString.call(new Function())) // [object Function] // 內(nèi)置普通對(duì)象本身 console.log(Object.prototype.toString.call(Math)) // [object Math] console.log(Object.prototype.toString.call(JSON)) // [object JSON] console.log(Object.prototype.toString.call(Reflect)) // [object Reflect] // 內(nèi)置函數(shù)對(duì)象本身 console.log(Object.prototype.toString.call(Array)) // [object Function] console.log(Object.prototype.toString.call(Map)) // [object Function] console.log(Object.prototype.toString.call(Function)) // [object Function] console.log(Object.prototype.toString.call(Object)) // [object Function] // 瀏覽器全局對(duì)象 console.log(Object.prototype.toString.call(document)) // [object HTMLDocument] console.log(Object.prototype.toString.call(window)) // [object Window] // 自定義構(gòu)造函數(shù) function Foo() {} f = new Foo(); console.log(Object.prototype.toString.call(f)) // [object object] console.log(Object.prototype.toString.call(Foo)) // [object Function]
(3)基于Object.prototype.toString.call()實(shí)現(xiàn)數(shù)據(jù)類型判斷
function getType(obj){ let type = typeof obj; if (type !== "object") { // 先進(jìn)行typeof判斷,如果是基礎(chǔ)數(shù)據(jù)類型,直接返回 return type; } // 對(duì)于typeof返回結(jié)果是object的,再進(jìn)行如下的判斷,正則返回結(jié)果 return Object.prototype.toString.call(obj).replace(/^[object (\S+)]$/, '$1'); // 注意正則中間有個(gè)空格 }
(4)總結(jié)
Object.prototype.toString.call() 能準(zhǔn)確判斷數(shù)據(jù)類型。
三、寫在最后
- 除了 Null 之外的原始數(shù)據(jù)類型,均可使用 typeof 判斷數(shù)據(jù)類型。
- Object.prototype.toString.call() 是判斷數(shù)據(jù)類型的最好的方法。
- 有關(guān) instanceof 和 constructor , 可以深入去了解JavaScript中的原型鏈。
到此這篇關(guān)于分享JavaScript 類型判斷的幾種方法的文章就介紹到這了,更多相關(guān)JavaScript 類型判斷內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
遨游,飛飛,IE,空中網(wǎng) 瀏覽器無(wú)提示關(guān)閉方法
遨游,飛飛,IE,空中網(wǎng) 瀏覽器無(wú)提示關(guān)閉方法,需要的朋友可以參考下。2011-07-07javascript模擬枚舉的簡(jiǎn)單實(shí)例
本篇文章主要是對(duì)javascript模擬枚舉的簡(jiǎn)單實(shí)例進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-03-03小程序安全指南之如何禁止外部直接跳轉(zhuǎn)到小程序某頁(yè)面
由于小程序跳轉(zhuǎn)的對(duì)象比較多,各自的規(guī)則又不一樣,因此小程序跳轉(zhuǎn)外部鏈接是用戶咨詢較多的問(wèn)題之一,下面這篇文章主要給大家介紹了關(guān)于小程序安全指南之如何禁止外部直接跳轉(zhuǎn)到小程序某頁(yè)面的相關(guān)資料,需要的朋友可以參考下2022-09-09JS 參數(shù)傳遞的實(shí)際應(yīng)用代碼分析
在項(xiàng)目中,有一個(gè)Ajax加載的區(qū)域,是一個(gè)Div標(biāo)簽,id為msg_box,這個(gè)控制鏈接包含在一個(gè)左側(cè)的導(dǎo)航中,當(dāng)從其他頁(yè)面鏈接到這個(gè)頁(yè)面時(shí),該JS代碼就失效了。2009-09-09淺談webpack 構(gòu)建性能優(yōu)化策略小結(jié)
webpack以其豐富的功能和靈活的配置而深受業(yè)內(nèi)吹捧,逐步取代了grunt和gulp成為大多數(shù)前端工程實(shí)踐中的首選,這篇文章主要介紹了淺談webpack 構(gòu)建性能優(yōu)化策略小結(jié),感興趣的小伙伴們可以參考一下2018-06-06js實(shí)現(xiàn)iframe跨頁(yè)面調(diào)用函數(shù)的方法
這篇文章主要介紹了js實(shí)現(xiàn)iframe跨頁(yè)面調(diào)用函數(shù)的方法,實(shí)例展示了iframe中父頁(yè)面調(diào)用子頁(yè)面和子頁(yè)面調(diào)用父頁(yè)面的實(shí)現(xiàn)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-12-12