Created
May 15, 2013 04:40
-
-
Save jdaly13/5581679 to your computer and use it in GitHub Desktop.
how to chain methods using an object literal (always return this)
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
var myBooze = { | |
booze:['wine', 'beer', 'liquor'], | |
chosenBooze:[], | |
getBooze: function (type) { | |
var booze_length = this.booze.length | |
for (i=0; i < booze_length; i++) { | |
if (type === this.booze[i]) { | |
this.chosenBooze.push(this.booze[i]); | |
return this | |
} else { | |
return false; | |
} | |
} | |
}, | |
consumption_style: function () { | |
var consumption; | |
var liquor = this.chosenBooze[0]; | |
if (liquor === 'wine') { | |
return "i got class" | |
} | |
} | |
} | |
myBooze.getBooze('wine').consumption_style() // this will return "I got class" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment