Skip to content

Instantly share code, notes, and snippets.

@yajd
Created February 28, 2014 22:47
Show Gist options
  • Select an option

  • Save yajd/9281666 to your computer and use it in GitHub Desktop.

Select an option

Save yajd/9281666 to your computer and use it in GitHub Desktop.
checking var types with obj.getproto
<!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