I want to assign object and it's method to prototype, My normal condition is something like
var Page = function (){
_page = {
id: 1,
getValue : function (){
},
UI : {
display : function (){
console.log('display layout');
}
}
}
return _page;
}
var mypage = new Page()
mypage.UI.display();
In my situation, there can be lot instances of Page class, so I want to intialize UI object with prototype, so UI and it's methods can be shared to all the Page instances. To achieve this, I can use __proto__
as following,
_page.__proto__.UI = {
display : function (){
console.log('display layout');
}
}
var Page = function (){
_page = {
id: 1,
getValue : function (){
}
}
_page.__proto__.UI = {
display : function (){
console.log('display layout');
}
}
return _page;
}
var mypage = new Page()
mypage.UI.display();
But this __proto__
is deprecated, so is there any better way that I can achieve this ?
Or
There is no need to initialize UI with prototype, we can use this as normal regardless of many Pages instances, Does this effect on performance ?