Created
December 17, 2013 02:10
-
-
Save gibbage/7998800 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> | |
<meta charset=utf-8 /> | |
<title>Setting content testing hasOwnProperty</title> | |
</head> | |
<body> | |
</body> | |
</html> |
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 allTheProperties(obj) { | |
$body.append('<h1>ALL THE PROPERTIES</h1>'); | |
var list = $('<ul>'); | |
for (var prop in obj) { | |
list.append('<li>' + prop + ' = ' + obj[prop] + '</li>'); | |
} | |
$body.append(list); | |
} | |
function objectsHasOwnProperty(obj) { | |
$body.append('<h1>object.hasOwnProperty</h1>'); | |
var list = $('<ul>'); | |
for (var prop in obj) { | |
if (obj.hasOwnProperty(prop)) { | |
list.append('<li>' + prop + ' = ' + obj[prop] + '</li>'); | |
} | |
} | |
$body.append(list); | |
} | |
function objectPrototypesHasOwnProperty(obj) { | |
$body.append('<h1>Object.prototype.hasOwnProperty</h1>'); | |
var list = $('<ul>'); | |
for (var prop in obj) { | |
if (Object.prototype.hasOwnProperty.call(obj, prop)) { | |
list.append('<li>' + prop + ' = ' + obj[prop] + '</li>'); | |
} | |
} | |
$body.append(list); | |
} | |
function Thing() { | |
this.prop1 = 'one'; | |
this.prop2 = 'two'; | |
this.prop3 = 'three'; | |
} | |
Thing.prototype.prop4 = 'four'; | |
Thing.prototype.prop5 = 'five'; | |
var thing = new Thing(); | |
var $body = $('body'); | |
allTheProperties(thing); | |
objectsHasOwnProperty(thing); | |
objectPrototypesHasOwnProperty(thing); | |
var winObj = window; | |
winObj.prop1 = 'one'; | |
winObj.prop2 = 'two'; | |
allTheProperties(winObj); | |
objectPrototypesHasOwnProperty(winObj); | |
objectsHasOwnProperty(winObj); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment