Last active
September 21, 2015 02:43
-
-
Save peterjacobson/f51e2ddac2a685967bdb to your computer and use it in GitHub Desktop.
Basic OOJS tree example
This file contains hidden or 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
// Write your Orange Tree code here - you may use constructor functions | |
var Tree = function(color) { | |
// this.age = age | |
this.color = color | |
} | |
Tree.prototype = { | |
age: 0, | |
grow: function() { | |
this.age ++ | |
}, | |
view: function() { | |
console.log('--------'); | |
console.log(this.color) | |
console.log('age', this.age) | |
console.log('--------'); | |
} | |
} | |
// Tree.prototype = { | |
// age: 2 | |
// } | |
var tree1 = new Tree('green') | |
var tree2 = new Tree('yellow') | |
tree1.grow() | |
tree1.view() | |
tree1.grow() | |
tree1.view() | |
tree2.view() | |
// chrome console log: | |
// typed-objects.js:14 -------- | |
// typed-objects.js:15 green | |
// typed-objects.js:16 age 1 | |
// typed-objects.js:17 -------- | |
// typed-objects.js:14 -------- | |
// typed-objects.js:15 green | |
// typed-objects.js:16 age 2 | |
// typed-objects.js:17 -------- | |
// typed-objects.js:14 -------- | |
// typed-objects.js:15 yellow | |
// typed-objects.js:16 age 0 | |
// typed-objects.js:17 -------- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment