';in';和';instanceOf';运算符的基本用法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了';in';和';instanceOf';运算符的基本用法相关的知识,希望对你有一定的参考价值。
Basic usage of the in and instanceOf operators.
function operators(){ //Use of in Operator var o = {x: 1, y: 2};//Create object var haveX = "x" in o;//true var haveY = "y" in o;//true var haveZ = "z" in o;//false var haveMethod = "toString" in o;//true (inherited property) console.log(haveX, haveY, haveZ, haveMethod); var a = [1, 2, 3]; var check1 = a instanceof Array;//true var check2 = a instanceof Object;//true (array is an object) var check3 = a instanceof RegExp;//false console.log(check1, check2, check3); var d = new Date(); var check1 = d instanceof Date;//true var check2 = d instanceof Object;//true var check3 = d instanceof Number;//false console.log(check1, check2, check3); }
以上是关于';in';和';instanceOf';运算符的基本用法的主要内容,如果未能解决你的问题,请参考以下文章