Using prefix `o` in ui5 javascript

I have seen people are using prefix o a lot when developing ui5 application.

var oRowsModel = new sap.ui.model.json.JSONModel();
    oValueHelpDialog.getTable().setModel(oRowsModel);
   if (oValueHelpDialog.getTable().bindRows){
    oValueHelpDialog.getTable().bindRows("/"); 
}

this.getView().setModel(oModel);

var oSelectedItem = oEvent.getParameter("selectedItem"),
            oTimeline = this.getView().byId("ActivityTimeline"),
            oTimelineBinding = oTimeline.getBinding("content");

Does it help somehow ? Is it a best practice ? What is the advantage?

I think that a lot of things are objects and specifying o does not help much. Why then to use it?

Answer

The prefixing of variables is just a naming convention carried over from the native SAP programming language called ABAP. In ABAP it is a long standing convention to prefix variables so that one can tell the type of the variable and if the variable is local or global, for instance lv_myvar for a local variable, and gt_mytab for a table type that is global. There is really no particular reason to continue with this practice in Javascript and UI5 – if you don´t like, don´t do it.

Leave a Reply

Your email address will not be published. Required fields are marked *