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
var beverages = ['juice', 'soda', 'beer'] | |
var func = function (thirsty, array, callback) { | |
array.push(thirsty); | |
var first = array[array.length - 1] | |
return callback(first); | |
} | |
func('water', beverages, function (param) { | |
return param |
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
//polyfill for Object.create | |
if (!Object.create) { | |
Object.create = function (o) { | |
if (arguments.length > 1) { | |
throw new Error('Object.create implementation only accepts the first parameter.'); | |
} | |
function F() {} | |
F.prototype = o; | |
return new F(); | |
}; |
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
//drinking will call chooseWisely and will look for it's liquor property | |
//within the liquor property is a wine property that will get output | |
var drinking = function (who) { | |
var which_spirit = this.liquor.wine; | |
console.log(which_spirit) // this will output malbec | |
return true | |
}; | |
var chooseWisely = function (ohdeliciouswine, brewski, whiskey) { |
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
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 { |
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
// with this you can write .end(3) instead of .end().end().end() | |
(function(){ | |
// Define overriding method. | |
jQuery.fn.end = function(no_of_times){ | |
var prevObject = this.prevObject; | |
if (!(arguments.length) || (typeof no_of_times !== "number")) { | |
return this.prevObject || this.constructor(null); | |
} else { |
NewerOlder