Consider the following JavaScript object definition :
var person = {
firstName: "John",
lastName : "Doe",
id : 5566,
fullName : function() {
return this.firstName + " " + this.lastName;
}
};
I know that if we want to use the object property(i.e. a function) we have to write the following code :
person.fullName();
As per my knowledge, JavaScript objects are containers for named values called properties or methods.
Also, I know that I can define the object properties like firstName, lastName, id as individual variables. Now, my question is can I also define the function "fullName" as a variable? If it is possible then how? and if not then why?
Thank You.
Yes
Here is simple answer with example to your question
with this structure you can write multiple functions ,first need to define function like
validatefunction
and then add into init