Created
July 8, 2014 10:50
-
-
Save noel9999/df833096354591a240d1 to your computer and use it in GitHub Desktop.
記錄一下自己寫的function,希望能做出像是ruby的inspect
This file contains 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
function my_inspect(object,isExclusive){ | |
isExclusive = typeof(isExclusive)!= "undefined" ? isExclusive : false | |
var result=[]; | |
for(var member in object){ | |
var type = typeof object[member]; | |
if(isExclusive){ | |
if (object.hasOwnProperty(member)) | |
result.push(member+"["+type+"] : "+object[member]); | |
} | |
else{ | |
result.push(member+"["+type+"] : "+object[member]); | |
} | |
} | |
return result.join('\n'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment