Safe way to declare a private function in Dojo

Template for creating private functions in Dojo?

The Dojo documentation advocates using _underscore to designate a function as private, but this is obviously just a convention and does not actually create a private function, for example.

define([
   "dojo/_base/declare"
],
function (declare) {
   return declare(null, {

       getPrivateData: function () {
           _myPrivateFunction();
       },

       _myPrivateFunction: function () {
           return "Data from private function";
       }
   });
});

I looked at SO questions about private variables in Dojo, but none of them reflect my requirement. However, one answer to this question includes a sample from the Dojo documentation showing how to create a private class.

My question is, is there a reason why the same template should not be used to create a private function? eg

 define([
"dojo/_base/declare"
],
function (declare) {

    var myPrivateFunction = function() {
        return "Data from private function";
    };

    return declare(null, {

        getPrivateData: function () {
            myPrivateFunction();
        }
    });

});
+4
source share

Source: https://habr.com/ru/post/1529425/


All Articles