Skip to content

Instantly share code, notes, and snippets.

@malachaifrazier
Created June 14, 2012 05:00
Show Gist options
  • Save malachaifrazier/2928063 to your computer and use it in GitHub Desktop.
Save malachaifrazier/2928063 to your computer and use it in GitHub Desktop.
undefined when checking array in Chrome?
//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);
<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