j s 중 유형 검사 방법
1392 단어 nodejs
1. typeof: 기본 유형 을 검사 하 는 데 사 용 됩 니 다.
typeof undefined;//=> undefined
typeof 'a';//=> string
typeof 1;//=> number
typeof true;//=> boolean
typeof {};//=> object
typeof [];//=> object
typeof function() {};//=> function
typeof null;//=> object
2. instanceof: 인용 형식 을 검사 하 는 데 사 용 됩 니 다 (왼쪽 은 대상 이 고 오른쪽 은 함수 입 니 다. 대상 의 원형 체인 에 따라 위로 찾 습 니 다. 원형 체인 에 오른쪽 함수 가 있 으 면 prototype 은 true 로 돌아 갑 니 다. 그렇지 않 으 면 false 로 돌아 갑 니 다)
var obj = {}; obj instanceof Object; //=> true;
var arr = []; arr instanceof Array; //=> true;
var fn = function() {}; fn instanceof Function; //=> true;
3. Object. prototype. toString. call (sth): 원형 체인 의 검 측 에 구멍 이 있 기 때문에 검 측 결과 가 정확 하지 않 기 때문에 이 형식 을 사용 할 수 있 습 니 다.
var toString = Object.prototype.toString;
toString.call(undefined);//=> [object Undefined]
toString.call(1);//=> [object, Number]
toString.call(NaN);//=> [object, Number]
toString.call('a');//=> [object, String]
toString.call(true);//=> [object, Boolean]
toString.call({});//=> [object, Object]
toString.call(function() {});//=> [object, Function]
toString.call([]);//=> [object, Array]
toString.call(null);//=> [object, Null]
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Node.js를 AWS서버에서 사용하는 실습간단한 예제와 함께 AWS에서 Node.js를사용하는 법을 배워보도록 하겠다. 해당 github에 있는 레포지토리로 사용을 할 것이다. 3000번 포트로 Listen되는 예제이고 간단히 GET, POST, DELET...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.