I'm trying to replicate vue.js just for the sake of learning. I do not understand the source code, I'm just going about it my way.
I have a class
class Relidon {
constructor(data) {
this.methods = data.methods
}
attributeHandler(node, attr, title){
if(title == 'clickDirective'){
node.addEventListener('click', function(e){
e.preventDefault(e);
this.methods.reverseMessage()
})
}
}
}
That's the framework and then I call it.
new Relidon({
el: 'r-app',
data: {
message: 'Hello People!',
age: '29',
something: 'testing',
seen: false,
attrTitle1: 'this is the first title',
attrTitle2: 'this is the second title',
},
methods: {
app: this,
reverseMessage: function () {
console.log(this.data.message)
}
}
})
(I removed all the code that deals with everything else so that you can see the real problem)
this
in app
refers to the window
object. How can I make this
refer to the object I created?