Skip to content

Instantly share code, notes, and snippets.

@karenpeng
Last active October 7, 2015 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karenpeng/07906cbf3b5fa4bedc80 to your computer and use it in GitHub Desktop.
Save karenpeng/07906cbf3b5fa4bedc80 to your computer and use it in GitHub Desktop.
Function.prototype.myBind = function(_this, _args){
var that = this
var args = Array.prototype.slice.call(arguments)
return function(){
//console.log(arguments)
var args1 = Array.prototype.slice.call(arguments)
var args2 = args.slice(1, args.length).concat(args1)
that.apply(_this, args2)
}
}
var a = function(){
console.log(this, arguments)
}
a.prototype.haha = function(){
console.log('haha')
}
var b = function(){
var happy = true
}
b.prototype.lol = function(){
console.log('lol')
}
var c = a.myBind(b, 1, 2, 3)
c(4, 5)
//Object {happy: true} [1, 2, 3, 4, 5]
// c.haha()
// VM3887:2 Uncaught TypeError: c.haha is not a function(…)(anonymous function) @ VM3887:2InjectedScript._evaluateOn @ VM2293:904InjectedScript._evaluateAndWrap @ VM2293:837InjectedScript.evaluate @ VM2293:693
// c.lol()
// VM3914:2 Uncaught TypeError: c.lol is not a function(…)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment