Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

When I go throw jquery.sap.global.js, there is PerfMeasurement class implementation. I am afraid there are two concerns in my mind.

Firstly there are two different patterns to implement a class, one is prototype pattern, such as Version:


function Version() {}
Version.prototype.InRange() {}






The another pattern is constructor. Such as PerfMeasurement.


function PerfMeasurement() {
     this._start = function() {};
     this.start = this['_start'];
}







According to _start function name, it should be a private function. But we could access this private function.


> jQuery.sap.measure._start
> function (sId, sInfo, aCategories) {
                if (!bActive) {
                    return;
                }
                aCategories = checkCategories(aCategories);
                if (!aCategories) {
                    return;
                }
                var iTime = jQuery.sap.now(…






Since private and public functions are defined in the same function scope, then private function could get function instance reference this, and public functions could access private functions. For example:


var JsClass = function(name) {
    var that = this;
    this.name = name;
    function _sayHello() {
        console.log('hello:', that.name);
    }
    this.say = function() {
        _sayHello();
    };
}
var instanceOfJsClass = new JsClass('Mike');
console.log('name:', instanceOfJsClass.name);
instanceOfJsClass.say();              // Access public function
instanceofJsClass._sayHello();     // Can't access private function






In the same way, _start could be removed bind from function instance reference this. And then _start function become a real private function, and the same time it could be accessed by other public functions.