开发者

How to overload a JavaScript function? (changing Slickgrid's editor)

开发者 https://www.devze.com 2023-03-22 03:12 出处:网络
I\'m using Slickgrid and I would like to change behavior of editor. Instead of copy&paste I tried to overload one of functions but it doesn\'t work. I cannot read loadValue function.

I'm using Slickgrid and I would like to change behavior of editor. Instead of copy&paste I tried to overload one of functions but it doesn't work. I cannot read loadValue function.

loadValue is defined as (some code omitted)

    IntegerCellEditor : function(args) {
        this.loadValue = function(item) {
            defaultValue = item[args.column.field];
            $input.val(defaultValue);
            $input[0].defaultValue = defaultValue;
            $input.select();
        };
    }

What I tried is:

    function tristateIntegerCellEditor(check_field) { 
        var f = IntegerCellEditor;
        var f_loadValue = f.loadValue;

        f.loadValue = function(item) {
            f_loadValue(item开发者_JAVA百科);

            if (check_field) {
                if (!item[check_field]) {
                    $select.disable();
                }
            }
        };

        return f;
    }

Is there any way to substitute my function?


You need f_loadValue.call(this, item);

Otherwise the old loadValue get's called with it's context (this) as window (the default).

Related:

  • Adding hooks
  • _.wrap
0

精彩评论

暂无评论...
验证码 换一张
取 消