Answer the question
In order to leave comments, you need to log in
How to make a property access through this inside the config of a new instance created on the basis of a class?
My instance has a VIEW property which is currently a function inside the object-argument(conf) of the new instance of MyClass. Now everything works, but how to make VIEW become a string (or object) and be declared as
VIEW: `${this.DATA.title}`
while this returns the conf area where this.DATA.title is equal to ' Title'. In this case, this returns Window.
class MyClass {
constructor(conf) {
/** public props */
this.ENTRY = conf.ENTRY;
this.DATA = conf.DATA;
/** instance methods */
// get dom element
conf.$ = (el) => {
var all = document.querySelectorAll(el);
return all.length > 1 ? all : document.querySelector(el);
}
/** inits */
conf.$(this.ENTRY).innerHTML = conf.VIEW();
conf.LOGIC();
}
die() {
conf.$(this.ENTRY).innerHTML = '';
}
}
var app = new MyClass({
ENTRY: '#app',
DATA: {
title: 'Title'
},
VIEW() {
return `
<h1>${this.DATA.title}</h1>
`
},
LOGIC() {
console.log(this.$('h1'))
},
});
Answer the question
In order to leave comments, you need to log in
and declared asImmediately at the time of the declaration there is a line. A primitive one that no longer refers to any this. Referenced at the time of the announcement, but as soon as it became a string - that's it.
VIEW: `${this.DATA.title}`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question