12. 자바스크립트
HTML
<button id="btn">Btn</button>
<div id="app">
<button @click="normal">normal function</button><br/>
<button @click="lambda">Lambda function</button>
</div>
Vue
let thisman = {
name: "I'am this man",
isthisok: function() {
console.log(this);
},
};
// thisman.isthisok();
let func = thisman.isthisok;
// func();
let btnElement = document.getElementById('btn');
//btnElement.addEventListener('click', thisman.isthisok);
//btnElement.addEventListener('click', () => console.log(this));
//btnElement.addEventListener('click', function(){console.log(this);});
let bindedFunc = thisman.isthisok.bind(thisman);
//btnElement.addEventListener('click', bindedFunc);
window.name = "I'am Window";
new Vue({
el: '#app',
data: {
name: "I'am Vue",
},
methods: {
normal: function() {
console.log(this.name);
},
lambda: () => console.log(this.name),
},
});