Merge pull request #749 from pelonpelon/patch-19

allow m.withAttr callback to determine its own `this` [non-breaking]
This commit is contained in:
Leo Horie 2015-08-03 09:35:00 -04:00
commit a9ab36388b
2 changed files with 10 additions and 2 deletions

View file

@ -851,11 +851,12 @@ var m = (function app(window, undefined) {
else m.endComputation();
}
m.withAttr = function(prop, withAttrCallback) {
m.withAttr = function(prop, withAttrCallback, callbackThis) {
return function(e) {
e = e || event;
var currentTarget = e.currentTarget || this;
withAttrCallback(prop in currentTarget ? currentTarget[prop] : currentTarget.getAttribute(prop));
var _this = callbackThis || this;
withAttrCallback.call(_this, prop in currentTarget ? currentTarget[prop] : currentTarget.getAttribute(prop));
};
};