Skip to content

Instantly share code, notes, and snippets.

@blake41
Created May 30, 2014 18:39
Show Gist options
  • Save blake41/3b718dbb23c2981874a9 to your computer and use it in GitHub Desktop.
Save blake41/3b718dbb23c2981874a9 to your computer and use it in GitHub Desktop.
Function.prototype.bind = function(that) {
var args = Array.prototype.slice.call(arguments)
return function() {
this.call(that, args)
}
}
var myobj = {
name : "blake",
colors : ["blue", "purple"],
forEach : function(array, action) {
for (var i = 0; i < array.length; i++)
action(array[i]);
},
calculate : function() {
this.forEach(this.colors, (function(e) {console.log(this.name)}).bind(this))
}
}
myobj.calculate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment