I have two constructor function, I just want to use object a
method in object b
without using new
keyword because I dont want to create an object with all its properties when there is no need. for example, inside constructor b
I want to use constructor b method.
function a(){
this.first=function(){
return 'aaaaaa'
}
this.last=function (){
return 'bbbbb'
}
}
function b(){
this.name= //call method last of constructor a.
}
var person= new b();
console.log(person.name) //bbbbb
Note: Constructor a contains two method. So In given example I do not have any use of method first but may required later on. So I don't want to create new a()
. I just want to call it directly