Skip to content

Instantly share code, notes, and snippets.

@dgloriaweb
Last active July 20, 2018 11:37
Show Gist options
  • Save dgloriaweb/d72eb30650b6835eda2770b4f193b955 to your computer and use it in GitHub Desktop.
Save dgloriaweb/d72eb30650b6835eda2770b4f193b955 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/garamex
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
document.write("object literal creates a reference type, so "
+"the change in the other makes change in the first one. "
+"This is called as singletons <p>")
var employee=
{
name:"John"
}
var newemployee = employee;
document.write("before changes: <br/>"+employee.name+"<br/>");
document.write(newemployee.name+"<br/>");
newemployee.name="Mary";
document.write("after changes: <br/>"+employee.name+"<br/>");
document.write(newemployee.name+"<br/>");
document.write("<p>The same using object constructor, doesn't change the initial value.<p>")
var Emp = function()
{
this.name="John";
}
var emp = new Emp;
var newemp = new Emp;
document.write("before changes: <br/>"+emp.name+"<br/>");
document.write(newemp.name+"<br/>");
newemp.name="Mary";
document.write("after changes: <br/>"+emp.name+"<br/>");
document.write(newemp.name+"<br/>");
</script>
<script id="jsbin-source-javascript" type="text/javascript">document.write("object literal creates a reference type, so "
+"the change in the other makes change in the first one. "
+"This is called as singletons <p>")
var employee=
{
name:"John"
}
var newemployee = employee;
document.write("before changes: <br/>"+employee.name+"<br/>");
document.write(newemployee.name+"<br/>");
newemployee.name="Mary";
document.write("after changes: <br/>"+employee.name+"<br/>");
document.write(newemployee.name+"<br/>");
document.write("<p>The same using object constructor, doesn't change the initial value.<p>")
var Emp = function()
{
this.name="John";
}
var emp = new Emp;
var newemp = new Emp;
document.write("before changes: <br/>"+emp.name+"<br/>");
document.write(newemp.name+"<br/>");
newemp.name="Mary";
document.write("after changes: <br/>"+emp.name+"<br/>");
document.write(newemp.name+"<br/>");
</script></body>
</html>
document.write("object literal creates a reference type, so "
+"the change in the other makes change in the first one. "
+"This is called as singletons <p>")
var employee=
{
name:"John"
}
var newemployee = employee;
document.write("before changes: <br/>"+employee.name+"<br/>");
document.write(newemployee.name+"<br/>");
newemployee.name="Mary";
document.write("after changes: <br/>"+employee.name+"<br/>");
document.write(newemployee.name+"<br/>");
document.write("<p>The same using object constructor, doesn't change the initial value.<p>")
var Emp = function()
{
this.name="John";
}
var emp = new Emp;
var newemp = new Emp;
document.write("before changes: <br/>"+emp.name+"<br/>");
document.write(newemp.name+"<br/>");
newemp.name="Mary";
document.write("after changes: <br/>"+emp.name+"<br/>");
document.write(newemp.name+"<br/>");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment