Skip to content

Instantly share code, notes, and snippets.

@ericpkatz
Created June 10, 2015 23:18
Show Gist options
  • Save ericpkatz/2177e68414d691a3ec88 to your computer and use it in GitHub Desktop.
Save ericpkatz/2177e68414d691a3ec88 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/wedexo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
console.clear();
function Foo(b){
this.counter = 0;
this.bar = b;
this.sayHi = function(){
console.log(this.bar);
};
this.SAYHI = function(){
var msg = this.bar + "!!!!!!";
console.log(msg);
this.counter = this.counter + 1;
};
}
var f1 = new Foo(42);
f1.SAYHI();
var f2 = new Foo(18);
var f3 = new Foo(7);
var arr = [ f2, f1, f3];
for(var i = 0; i < arr.length; i++){
arr[i].SAYHI();
}
console.log(f1.counter);
console.log(f2.counter);
</script>
<script id="jsbin-source-javascript" type="text/javascript">console.clear();
function Foo(b){
this.counter = 0;
this.bar = b;
this.sayHi = function(){
console.log(this.bar);
};
this.SAYHI = function(){
var msg = this.bar + "!!!!!!";
console.log(msg);
this.counter = this.counter + 1;
};
}
var f1 = new Foo(42);
f1.SAYHI();
var f2 = new Foo(18);
var f3 = new Foo(7);
var arr = [ f2, f1, f3];
for(var i = 0; i < arr.length; i++){
arr[i].SAYHI();
}
console.log(f1.counter);
console.log(f2.counter);
</script></body>
</html>
console.clear();
function Foo(b){
this.counter = 0;
this.bar = b;
this.sayHi = function(){
console.log(this.bar);
};
this.SAYHI = function(){
var msg = this.bar + "!!!!!!";
console.log(msg);
this.counter = this.counter + 1;
};
}
var f1 = new Foo(42);
f1.SAYHI();
var f2 = new Foo(18);
var f3 = new Foo(7);
var arr = [ f2, f1, f3];
for(var i = 0; i < arr.length; i++){
arr[i].SAYHI();
}
console.log(f1.counter);
console.log(f2.counter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment