I am extending a javascript class which has an import myParseFloat
. An error is thrown that a child class does not have access to myParseFloat
. What is the best approach to pass this function to a class extending a class? Importing the functions additionally on the child seems the easiest, but I am guessing incorrect. I would like to access myParseFloat directly, but i could use this.myParseFloat if needed.
TableView.js
import {myParseFloat, round2} from '../../lib/math';
export default class TableView {
constructor(model){
console.log(myParseFloat('1.2333445'));
}
}
DataTableView.js
import TableView from './TableView';
export default class DataTableView extends TableView {
constructor(model) {
super(model);
console.log(myParseFloat('1.2333445')); //myParseFloat is not available
}
}
Imports in javascript are exclusive to the module, so you'll need the line in both files.
Actually there is a way to achieve this
import {myParseFloat, round2} from '../../lib/math';
export default class TableView {
constructor(model){
this.myParseFloat = myParseFloat;
this.round2 = round2;
}
}
And in child class
import TableView from './TableView';
export default class DataTableView extends TableView {
constructor(model) {
super(model);
console.log(this.myParseFloat('1.2333445'));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With