I need a way to call many DHTMLX attach*() functions with certain defaults already set. This is just one example. If I can figure this one example out then I can apply it to all others.
DHTMLX has many functions similar to this: dhtmlXCellObject.prototype.attachToolbar(), attachTabbar(), attachRibbon(), etc... But for every single toolbar in my app there are certain settings I want to automatically apply like iconSize and iconPath.
dhtmlXCellObject.prototype.attachTheBetterToolbar = function (conf) {
// https://docs.dhtmlx.com/api__dhtmlxlayout_attachtoolbar.html
// dhtmlXToolbarObject.prototype.attachToolbar.call(this, conf); This throws: Cannot read property 'call' of undefined
this.attachToolbar.call(this, conf);
// I want these two settings below on every single toolbar in our app but
// I only want to have to set them once in here. Then throughout my
// entire application, we will only use attachTheBetterToolbar...
// layout.cells('a').attachTheBetterToolbar()
// window.attachTheBetterToolbar()
// accordian.attachTheBetterToolbar()
// tabbar.tabs('a').attachTheBetterToolbar()
// etc...
this.setIconSize(18);
this.setIconsPath(c3.iconPath);
};
The above code doesn't work (errors with: this.setIconSize is not a function) but I think you'll get the idea of what I'm trying to attempt. I'm reading all sorts of articles on JavaScript extend, apply, call, inheritance, etc... I feel like I'm close but something just isn't clicking.
I thought the ".call()" part would cause inheritance to happen like described here: https://stackoverflow.com/a/16058530/3112803 (the Variation 1 - Mixin -> Inheritance example)
var t = dhtmlXLayout.cells('a').attachTheBetterToolbar();.call().this.attachToolbar(conf)should do the same thing..call()if you wantthisin the called method to be different from the object whose method you're using.