News for hackers. Stuff that matters.
Re:Classes are Expressions by rmrfrmrf on Thursday June 04, 2015 @05:57PM (#9662406)
sure :P (EDIT: Just kidding; the parent's point totally flew over my head). I've actually created classes this way in the past when I worked with a team of enterprise Java developers lol. You could also make magic getter/setter methods if you really wanted to get crazy with it.

    var Person = (function() {
        return function(firstName, lastName) {
            var privateVars = {
                firstName: "",
                lastName: ""
            };

            this.getFirstName = function() {
                return privateVars.firstName;
            };

            this.setFirstName = function(firstName) {
                privateVars.firstName = firstName;
                return this;
            };

            this.getLastName = function() {
                return privateVars.lastName;
            }

            this.setLastName = function(lastName) {
                privateVars.lastName = lastName;
                return this;
            };

            this.sameFirstName = function(otherPerson) {
                return this.getFirstName() == otherPerson.getFirstName();
            }

            this.setFirstName(firstName);
            this.setLastName(lastName);
            Object.freeze(this);
            return this;
        }
    }());

    var p = new Person("John", "Doe");
    var q = new Person("John", "Smith");
    var r = new Person("Jane", "Doe");

    p.sameFirstName(q); // true
    p.sameFirstName(r); // false
Re:Classes are Expressions by Cushman on Thursday June 04, 2015 @06:17PM (#9662514)
This isn't quite the same; the parent is pointing out that you can implement `sameFirstName` without exposing `firstName` publicly at all, not even as a getter.
Re:Classes are Expressions by rmrfrmrf on Thursday June 04, 2015 @06:28PM (#9662584)
Oh wow, I totally missed that. Thanks for clarifying!
Re:Classes are Expressions by Cushman on Thursday June 04, 2015 @06:49PM (#9662717)
Np! Mind it is technically possible to do, check out my sibling comment if you haven't already.