Alternative code to classes in Javascript? I'm new to JavaScript and came across classes in ES6. Though they are great, I don't want to learn something that can be done in other ways. So, I created this code that does somehow similar job to what classes in JS do. Please give me feedback on whether classes does more than what I think they can do and whether my code is missing something that classes can do.
This is the JS code:

&lt;script&gt;
const person = function(first, second, age, sex){
    return {
        firstName:first,
        lastName:second,
        age:age,
        gender:sex,
        fullName:function(){
            return this.firstName + " " + this.lastName;
        }
    }
}
var John = person("John", "Anderson", 21, "Male");
var Mary = person("Mary", "Smith", 32, "Female");

document.getElementById("demo1").innerHTML = John.firstName;
document.getElementById("demo2").innerHTML = Mary.fullName();
&lt;/script&gt;


And the output of the code is: 

John

Mary Smith
A short review;


In stacktraces, person will be a nameless function, use function person(){} instead
There is no good reason to have different names (first->firstName) for your attributes. Using the same name allows you to use some nifty JS syntax
Your code will create a new function for each instance of person, unless you have a smart VM, that could be heavy on memory
I would extend the .prototype of person for fullName to prevent that memory issue
I also strive to name functions with a &lt;verb&gt;&lt;thing&gt; scheme so I would call it getFullName()
Ideally functions that are akin to a class are capitalized, so person -> Person


So, all in all, this is my counter proposal:



    function Person(firstName, lastName, age, gender){
      Object.assign(this, {firstName, lastName, age, gender});
    }

    Person.prototype.getFullName = function personGetFullName(){
      return this.firstName + " " + this.lastName;
    }

    const John = new Person("John", "Anderson", 21, "Male");
    const Mary = new Person("Mary", "Smith", 32, "Female");
    console.log(John.firstName);
    console.log(Mary.getFullName());