I need to run a method belonging to all instances of an object. For example, if I had the method fullName(), which concatenates .firstName and .secondName, I would like to do it for both instances of the object in the code:
<script>
function x(firstName, secondName) {
this.firstName = firstName;
this.secondName = secondName;
this.fullName = function() {
console.log(this.firstName + this.secondName); //this should output result of both john.fullName() and will.fullName()
}
}
var john = new x("John ", "Smith");
var will = new x("Will ", "Adams");
</script>
How is this accomplished in javascript? Preferably, it would be without specifying the number of instances, and instead just running the method for all instances that have been created. Thanks in advance.