Last active
April 4, 2017 01:15
-
-
Save kkeeth/3ef1a2ee492f2d51b8c255e08b96a9e0 to your computer and use it in GitHub Desktop.
JavaScriptに関するスニペット一覧
This file contains hidden or 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
(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