简体   繁体   English

在ui5 javascript中使用前缀`o`

[英]Using prefix `o` in ui5 javascript

I have seen people are using prefix o a lot when developing ui5 application. 我已经看到人们在开发ui5应用程序时经常使用前缀o

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. 我认为很多东西都是对象,指定o并没有太大帮助。 Why then to use it? 为什么要使用它?

The prefixing of variables is just a naming convention carried over from the native SAP programming language called ABAP. 变量的前缀只是从本地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. 在ABAP中,为变量加上前缀是一种长期的惯例,这样就可以知道变量的类型以及变量是本地变量还是全局变量,例如lv_myvar表示局部变量,gt_mytab表示全局表类型。 There is really no particular reason to continue with this practice in Javascript and UI5 - if you don´t like, don´t do it. 确实没有特别的理由继续在Javascript和UI5中继续这种做法-如果您不喜欢,请不要这样做。

o for Object maybe? o可能是对象? :) :)

Plus it makes sense, to append an 'o' to your variable name,as you shall be fiddling around with objects all the time. 另外,在变量名后加上“ o”是很有意义的,因为您将一直在摆弄对象。

Plus, it helps much to use oList instead of List, as it is a control. 另外,使用oList代替List很有帮助,因为它是一个控件。

o means object. o表示对象。 You can see here 你可以在这里看到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM