Created
November 7, 2014 15:30
-
-
Save davidyang013/7798836a545856f2f47c to your computer and use it in GitHub Desktop.
Print js Object properties
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
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>Events</title> | |
<script type="text/javascript" src="http://www.google.com/jsapi"></script> | |
<script type="text/javascript"> | |
google.load("jquery", "1.4.2"); | |
</script> | |
<script language="javascript" type="text/javascript"> | |
$(document).ready(function() { | |
var getAllMethods = function(obj){ | |
var fn_filter = function(property) { return typeof obj[property] == 'function'; } | |
var attr_filter = function(property) { return typeof obj[property] != 'function'; } | |
var fn_Name = function (obj){ return obj.match(/^function\s(\w*)\(\)\s*\{\s*\[native\scode\]\s\}$/); } | |
var list=[]; | |
//var objs = [obj,obj["__proto__"],obj["prototype"]]; | |
var obj_name = fn_Name(obj.toString())[1]; | |
var l = []; | |
list.push("<h2>"+obj_name+"</h2>"); | |
list.push(Object.getOwnPropertyNames(obj)); | |
list.push("<h2>"+obj_name+".__proto__</h2>"); | |
list.push(Object.getOwnPropertyNames(obj['__proto__'])); | |
list.push("<h2>"+obj_name+".prototype</h2>"); | |
list.push(Object.getOwnPropertyNames(obj['prototype'])); | |
return list; | |
} | |
$("#btn").click(function(){ | |
$('#div2').empty().append(getAllMethods(eval($("#obj").val())).toString()); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<input type="text" id="obj" name="obj" /><input id="btn" type="button" value="seach"/><br/> | |
<div id="div1"><p>Print API:</p> </div> | |
<div id="div2"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment