Created
September 9, 2014 12:36
-
-
Save timkg/b85ba53b7e1bdb73d4e1 to your computer and use it in GitHub Desktop.
// source http://jsbin.com/govubetamoli/3
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var myObj = { | |
property: 1, | |
sendTo: function (endpoint) { | |
console.log('sending ' + this.property + ' to ' + endpoint); | |
} | |
}; | |
function format () { | |
console.log('formatting ' + this.property); | |
} | |
function log () { | |
console.log('logging ' + this.property); | |
} | |
before(myObj, 'sendTo', format); | |
after(myObj, 'sendTo', log); | |
function before (object, method, fn) { | |
var originalMethod = object[method]; | |
object[method] = function () { | |
fn.apply(object); | |
originalMethod.apply(object, arguments); | |
}; | |
} | |
function after (object, method, fn) { | |
var originalMethod = object[method]; | |
object[method] = function () { | |
originalMethod.apply(object, arguments); | |
fn.call(object); | |
}; | |
} | |
myObj.sendTo('backend'); | |
</script> | |
</body> | |
</html> |
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 myObj = { | |
property: 1, | |
sendTo: function (endpoint) { | |
console.log('sending ' + this.property + ' to ' + endpoint); | |
} | |
}; | |
function format () { | |
console.log('formatting ' + this.property); | |
} | |
function log () { | |
console.log('logging ' + this.property); | |
} | |
before(myObj, 'sendTo', format); | |
after(myObj, 'sendTo', log); | |
function before (object, method, fn) { | |
var originalMethod = object[method]; | |
object[method] = function () { | |
fn.apply(object); | |
originalMethod.apply(object, arguments); | |
}; | |
} | |
function after (object, method, fn) { | |
var originalMethod = object[method]; | |
object[method] = function () { | |
originalMethod.apply(object, arguments); | |
fn.call(object); | |
}; | |
} | |
myObj.sendTo('backend'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment