Created
June 14, 2012 05:00
-
-
Save malachaifrazier/2928063 to your computer and use it in GitHub Desktop.
undefined when checking array in Chrome?
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
//The USER | |
function User(name, role){ | |
this.beats = []; //num of beats goes here | |
this.name = name; | |
this.role = role; | |
this.addBeats = function(numbeats){ | |
return this.beats.push(numbeats); | |
}; | |
this.reset = function(beats){ | |
this.beats.length = 0; | |
return this.beats; | |
}; | |
} | |
// Three New Instances. Three New Users. | |
var Mal = new User("Mal", "Rapper"); | |
Mal.addBeats(["love", "cash"]); | |
var Dan = new User("Dan", "Producer"); | |
Dan.addBeats(["cake","dirt","sally-mae"]); | |
var Tom = new User("Tom", "Producer"); | |
Tom.addBeats(["Fun","Little","Samsung", "Turtle", "PC"]); | |
console.log(Tom.beats); // undefined with reset called on Tom? | |
console.log(Mal.beats); // undefined with reset called on Mal? | |
console.log(Dan.beats); // undefined with reset called on Dan? | |
// Reset everybody's [beats] array | |
Dan.reset(); | |
Tom.reset(); | |
Mal.reset(); | |
// Check for empty arrays | |
console.log(Mal.beats); | |
console.log(Dan.beats); | |
console.log(Tom.beats); |
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> | |
<head> | |
<script type="text/javascript" src="javascript.js"></script> | |
</head> | |
<body> | |
<h1>Tester</h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment