Skip to content

Instantly share code, notes, and snippets.

@rubyonrailstutor
Created June 27, 2012 00:21
Show Gist options
  • Save rubyonrailstutor/3000426 to your computer and use it in GitHub Desktop.
Save rubyonrailstutor/3000426 to your computer and use it in GitHub Desktop.
prototype in js description
<html>
<head>
<script type="text/javascript">
if (typeof Object.create !== 'function') {
Object.create = function (o) {
var F = function () {};
F.prototype = o;
return new F();
};
};
var parent = {
first_name: "john",
last_name: "davison"
};
var child = Object.create(parent);
child.hobby = "skating"
child.first = "johnny"
function check_relationship(){
var parent = {
first_name: "mike",
last_name: "someone"
};
var child = Object.create(parent);
child.hobby = "surfing"
child.first = "baby mike"
alert("the parent is" + " " + child.first_name + " " + child.last_name + ", " + child.first + " " + "is the first child")
}
</script>
</head>
<body>
<form>
<input type="submit" value="check_relationship" onclick="check_relationship()">
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment