-1

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)

7
  • What does your instantiation look like? Commented Jun 15, 2018 at 21:27
  • var t = dhtmlXLayout.cells('a').attachTheBetterToolbar(); Commented Jun 15, 2018 at 21:29
  • Not sure why you need to use .call(). this.attachToolbar(conf) should do the same thing. Commented Jun 15, 2018 at 21:32
  • You only need to use .call() if you want this in the called method to be different from the object whose method you're using. Commented Jun 15, 2018 at 21:34
  • Thanks @Barmar, been on a coding bender, crosseyed. Add it as an answer if you want credit. Editing OP now to show what I just tried which works. Commented Jun 15, 2018 at 21:39

1 Answer 1

0

This does what I need...

dhtmlXCellObject.prototype.attachTheBetterToolbar = function (conf) {
    var tb = this.attachToolbar(conf);

    // this.setIconset("awesome");
    tb.setIconSize(18);
    tb.setIconsPath(c3.iconPath);

    return tb;
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.