imaging that: you have some object in your program(with JS language) and you have some name:value
in your object with any data type.
if we say any data type that can be to this mean we want write a name:value and "value" be a function?
Ofcourse!!
if function situation is to be that, function take two parameters and then return their in output, and if we want specify our parameters from a another object we can use call
method!
example:
const x = {
fullName: function(){
return this.name + " " + this.lName
}
};
But where is name or lName(last name)?
is here: (in another object, we take from this object)
const object1 = {
name: "ana",
lName: "amini"
}
So now we achieve to method part
:
console.log(x.fullName.call(object1));
and then output will be like that:
ana amini
Tip(1): for showing a value of the name in object we use from this rule: objectName.name1
;
Tip(2): we use " "
in our function, so our values are separate from each other!
;)!
Top comments (2)
thank you!