Skip to content

Instantly share code, notes, and snippets.

@kkeeth
Last active April 4, 2017 01:15
Show Gist options
  • Save kkeeth/3ef1a2ee492f2d51b8c255e08b96a9e0 to your computer and use it in GitHub Desktop.
Save kkeeth/3ef1a2ee492f2d51b8c255e08b96a9e0 to your computer and use it in GitHub Desktop.
JavaScriptに関するスニペット一覧
(function() {
var app = { name: 'fuga' };
// bindパターン1
var t = document.getElementById('hoge');
t.addEventListener('click', function(ev) {
console.log(ev.target.tagName); // DIV
console.log(this); // fuga
}.bind(app));
// bindパターン2
app.piyo = function(){
var t = document.getElementById('hoge');
t.addEventListener('click', function(ev) {
console.log(ev.target.tagName); // DIV
console.log(this); // fuga
}.bind(this)); // app自身ですよ
};
app.piyo();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment