Last active
November 3, 2017 05:29
-
-
Save dohoons/46163c4739831dfb19fa66eaa7d05554 to your computer and use it in GitHub Desktop.
addDocumentEvent
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
// document 이벤트 | |
var addDocumentEvent = function(eventList) { | |
return function(types, cb) { | |
var typeList = types.split(' '); | |
var type = ''; | |
if(typeof cb !== 'function') return false; | |
for(var i = typeList.length; i--;) { | |
type = typeList[i]; | |
if(eventList.hasOwnProperty(type)) { | |
eventList[type].push(cb); | |
} else { | |
eventList[type] = [cb]; | |
document.addEventListener(type, function(e) { | |
for(var j = eventList[type].length; j--;) { | |
eventList[type][j].call(this, e); | |
} | |
}); | |
} | |
} | |
}; | |
}({}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment