JavaScript/jQuery
[jQuery] jQuery.type() 함수 구현해보기
뚱2
2012. 2. 8. 13:47
욜심히 만들었더니 jQuery.type() 이란 메소드가 있다. ㅡㅡ; 찾아볼걸...
// getType(true) "boolean"를 리턴 // getType(1) "number"를 리턴 // getType(1.1) "number"를 리턴 // getType("") "string"를 리턴 // getType(function(){}) "function"를 리턴 // getType(new Date()) "date"를 리턴 // getType(/^$/) "regexp"를 리턴 function getType(obj) { var msg = "undefined" ,myObj = obj ; if ( myObj != null ) { var strType = Object.prototype.toString.call(myObj); var match = strType.match(/^\[object (.+)\]$/i); msg = match && match[1].toLowerCase(); } return msg; }