[ "iife-wrap"] 플러그인이있는 ES6 + 바벨을 사용하고 있습니다.ES6에서 값 유형 가져 오기
이전에 작성한 (양식 유효성 검사) 플러그인을 다시 작성하려고합니다. 데이터가 객체인지 확인하려고합니다. typeof blah === 'object'
또는 내가 ES6에 넣어 그러나 경우 string, function, and etc.
:
은 ES5를 들어 이것은 단지이다. 오류가 발생합니다. 유형 오류 : _typeof는 함수가 아닙니다.
다음은 내 코드 샘플입니다.
let es6function =() => {
return 'asd';
}
console.log(typeof es6function)
class Person {
}
let tryThis = new Person()
console.log(tryThis instanceof Person)
ES5는 :
;
(function() {
'use strict';
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
var _typeof = typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol" ? function (obj) {
return typeof obj === 'undefined' ? 'undefined' : _typeof(obj);
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === 'undefined' ? 'undefined' : _typeof(obj);
};
var es6function = function es6function() {
return 'asd';
};
console.log(typeof es6function === 'undefined' ? 'undefined' : _typeof(es6function));
var Person = function Person() {
_classCallCheck(this, Person);
};
var tryThis = new Person();
console.log(tryThis instanceof Person);
})();
어떤 도움
주시면 감사하겠습니다 후 컴파일. 감사.
이것은 거의 transpiler (babel)와 관련이 있습니다. 기본적으로 ES6을 지원하는 브라우저에서 예상대로 작동합니다. – rvighne
나를 위해 잘 작동하는 것 같아 오류가'_typeof', 당신은 오타가 없다고 확신합니까 – adeneo
나는 transpiled 것을 의미합니다. 잠깐, 내가 편집 할게. –