Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private fields are not private. #3151

Closed
stevenbey opened this issue May 13, 2015 · 1 comment
Closed

Private fields are not private. #3151

stevenbey opened this issue May 13, 2015 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@stevenbey
Copy link

When declaring a private field, the resulting JavaScript is:

var Example;
(function (Example) {
    var Test = (function () {
        function Test() {
            this._value = 0;
        }
        Object.defineProperty(Test.prototype, "value", {
            get: function () {
                return this._value;
            },
            enumerable: true,
            configurable: true
        });
        return Test;
    })();
    Example.Test = Test;
})(Example || (Example = {}));

However, this means that private fields are visible when inspecting the object (e.g. using the console.dir method) and, therefore, aren't truly private.

I suggest moving the declaration of private fields to the scope of the containing anonymous function:

var Example;
(function (Example) {
    var Test = (function () {
        var _value = 0;
        function Test() {
        }
        Object.defineProperty(Test.prototype, "value", {
            get: function () {
                return _value;
            },
            enumerable: true,
            configurable: true
        });
        return Test;
    })();
    Example.Test = Test;
})(Example || (Example = {}));
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 13, 2015
@RyanCavanaugh
Copy link
Member

See existing issues #1537 and #564

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants