Created
February 28, 2014 22:47
-
-
Save yajd/9281666 to your computer and use it in GitHub Desktop.
checking var types with obj.getproto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <body> | |
| <script> | |
| /* | |
| function Animal() {} | |
| var b = new Animal; | |
| try { | |
| console.log(Object.getOwnPropertyNames(b)) //[object Array] | |
| console.log(Object.getPrototypeOf(b)) //[object Object] //constructor: Function, __proto__:Object //constructor: name: Animal | |
| } catch (ex) { | |
| console.log(ex) | |
| console.log(typeof(b)) | |
| } | |
| */ | |
| /* | |
| var b = ['j','k','l']; | |
| try { | |
| console.log(Object.getOwnPropertyNames(b)) //[object Array] // | |
| console.log(Object.getPrototypeOf(b)) //[object Array] | |
| } catch (ex) { | |
| console.log(ex) | |
| console.log(typeof(b)) | |
| } | |
| */ | |
| /* | |
| var b = null; | |
| try { | |
| console.log(Object.getPrototypeOf(b)) | |
| console.log(Object.getOwnPropertyNames(b)) | |
| } catch (ex) { | |
| console.log(ex)//b is not an object | |
| console.log(typeof(b)) //object | |
| } | |
| */ | |
| /* | |
| var b = undefined; | |
| try { | |
| console.log(Object.getPrototypeOf(b)) | |
| console.log(Object.getOwnPropertyNames(b)) | |
| } catch (ex) { | |
| console.log(ex)//b is not an object | |
| console.log(typeof(b)) //undefined | |
| } | |
| */ | |
| /* | |
| var b = function rawr(){}; | |
| try { | |
| console.log(Object.getPrototypeOf(b)) //[object Function] //name: '',constructor: Function >> name:Function | |
| console.log(Object.getOwnPropertyNames(b)) //[object Array] // | |
| } catch (ex) { | |
| console.log(ex)//b is not an object | |
| console.log(typeof(b)) //undefined | |
| } | |
| */ | |
| function b(){}; | |
| try { | |
| console.log(Object.getPrototypeOf(b)) //[object Function] //name: '',constructor: Function >> name:Function | |
| console.log(Object.getOwnPropertyNames(b)) //[object Array] // | |
| } catch (ex) { | |
| console.log(ex)//b is not an object | |
| console.log(typeof(b)) //undefined | |
| } | |
| </script> | |
| </body> | |
| </html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment