admin管理员组文章数量:1402367
I was trying to implement Component.js in my SAPUI5 application but unable to understand .extend & .prototype.init.apply method in below piece of code.
sap.ui.define([
"sap/ui/core/UIComponent"
], function (UIComponent) {
"use strict";
return UIComponent.extend(""** , {**
init: function () {
UIComponent.prototype.init.apply(this, arguments);
// console.log(UIComponent.extend);
UIComponent.prototype.init.apply(this, arguments);
}
});
});
Can someone please explain?
P.S. I am beginner to OO Javascript.
I was trying to implement Component.js in my SAPUI5 application but unable to understand .extend & .prototype.init.apply method in below piece of code.
sap.ui.define([
"sap/ui/core/UIComponent"
], function (UIComponent) {
"use strict";
return UIComponent.extend(""** , {**
init: function () {
UIComponent.prototype.init.apply(this, arguments);
// console.log(UIComponent.extend);
UIComponent.prototype.init.apply(this, arguments);
}
});
});
Can someone please explain?
P.S. I am beginner to OO Javascript.
Share Improve this question asked Mar 29, 2016 at 11:36 RahulRahul 1513 silver badges17 bronze badges 02 Answers
Reset to default 5What they're doing here is very Java-ish. With extend
they're creating a subclass of UIComponent
.
In this subclass the init
method is overridden. When you override a method of the parent object, it's a good practice to call the parents original method from the method that overrides it. By doing so, you're avoiding unexpected situations such as variables that have not been defined at the parent etc. Calling the parent's original method is exactly what the init.apply
statement is doing. It's doesn't make sense to me to do this twice though.
To give you some hints:
extend es from from sap.ui.base.Object which delegates to sap.ui.base.ManagedObject.createClass(). Thanks to @schnoedel to point it out.
prototype.init.apply and arguments object.
本文标签: javascriptPrototype amp Extend in SAPUI5 (Componentjs)Stack Overflow
版权声明:本文标题:javascript - Prototype & Extend in SAPUI5 (Component.js) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744351351a2602069.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论