0

I need quick help regarding calling a function within a function using Magento knockout js, I have tried this

define([
    'ko',
    'uiComponent'
], function (ko, Component) {
    'use strict';

    return Component.extend({
        initialize: function () {
            //initialize parent Component
            this._super();
        },

        testfunctionout: function() {
        var self = this;
            console.log(' in testfunctionout');
        self.testfunctionin();
        },

        testfunctionin: function() {
            console.log(' in testfunctionin');
        }

    });
});

Can anyone help me out? Thanks in advance.

1
  • What error you got in console? Did you called testfunctionout function? Oct 15, 2019 at 6:53

2 Answers 2

2

use self under initailize function dont declare it under testfunctionOut

 initialize: function () {
            self = this;
 }
 testfunctionout: function() {
        console.log(' in testfunctionout');
    self.testfunctionin();
    },

    testfunctionin: function() {
        console.log(' in testfunctionin');
    }
0

Try this:

define([
    'ko',
    'uiComponent'
], function (ko, Component) {
    'use strict';

    return Component.extend({
        initialize: function () {
            //initialize parent Component
            var self = this;
            this._super();
        },

        testfunctionout: function() {
            console.log('in testfunctionout');
            this.testfunctionin();
        },

        testfunctionin: function() {
            console.log(' in testfunctionin');
        }

    });
});
3

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.