#privatefields — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #privatefields, aggregated by home.social.
-
Private Fields Use # Symbol?!
Private fields are HIDDEN! The # symbol makes properties truly private. You can't access them from outside, even with bracket notation. This is REAL privacy!
#javascript #javascripttricks #privatefields #symbol #encapsulation #javascriptweird #javascriptquiz #codingchallenge #javascriptshorts #javascriptwtf #classprivacy #advancedjavascript
-
Private Fields Use # Symbol?!
Private fields are HIDDEN! The # symbol makes properties truly private. You can't access them from outside, even with bracket notation. This is REAL privacy!
#javascript #javascripttricks #privatefields #symbol #encapsulation #javascriptweird #javascriptquiz #codingchallenge #javascriptshorts #javascriptwtf #classprivacy #advancedjavascript
-
Private Fields Use # Symbol?!
Private fields are HIDDEN! The # symbol makes properties truly private. You can't access them from outside, even with bracket notation. This is REAL privacy!
#javascript #javascripttricks #privatefields #symbol #encapsulation #javascriptweird #javascriptquiz #codingchallenge #javascriptshorts #javascriptwtf #classprivacy #advancedjavascript
-
Private Fields Use # Symbol?!
Private fields are HIDDEN! The # symbol makes properties truly private. You can't access them from outside, even with bracket notation. This is REAL privacy!
#javascript #javascripttricks #privatefields #symbol #encapsulation #javascriptweird #javascriptquiz #codingchallenge #javascriptshorts #javascriptwtf #classprivacy #advancedjavascript
-
Private Fields Use # Symbol?!
Private fields are HIDDEN! The # symbol makes properties truly private. You can't access them from outside, even with bracket notation. This is REAL privacy!
#javascript #javascripttricks #privatefields #symbol #encapsulation #javascriptweird #javascriptquiz #codingchallenge #javascriptshorts #javascriptwtf #classprivacy #advancedjavascript
-
What is the difference between extending a subclass of an object and `Object.create`-ing based on a prototype for the purposes of JS private fields? I'm surprised to get different behavior between:
```javascript
class Foo {
#foo = 'foo';doSomething(): void {
console.log(this.#foo);
}
}class Bar extends Foo {}
new Foo().doSomething(); // Works
new Bar().doSomething(); // Works
Object.create(new Foo()).doSomething(); // ERROR: Cannot read private member.
```In my mind, they should create basically the same prototype inheritance. Why does `Object.create` fail?
-
What is the difference between extending a subclass of an object and `Object.create`-ing based on a prototype for the purposes of JS private fields? I'm surprised to get different behavior between:
```javascript
class Foo {
#foo = 'foo';doSomething(): void {
console.log(this.#foo);
}
}class Bar extends Foo {}
new Foo().doSomething(); // Works
new Bar().doSomething(); // Works
Object.create(new Foo()).doSomething(); // ERROR: Cannot read private member.
```In my mind, they should create basically the same prototype inheritance. Why does `Object.create` fail?
-
What is the difference between extending a subclass of an object and `Object.create`-ing based on a prototype for the purposes of JS private fields? I'm surprised to get different behavior between:
```javascript
class Foo {
#foo = 'foo';doSomething(): void {
console.log(this.#foo);
}
}class Bar extends Foo {}
new Foo().doSomething(); // Works
new Bar().doSomething(); // Works
Object.create(new Foo()).doSomething(); // ERROR: Cannot read private member.
```In my mind, they should create basically the same prototype inheritance. Why does `Object.create` fail?
-
What is the difference between extending a subclass of an object and `Object.create`-ing based on a prototype for the purposes of JS private fields? I'm surprised to get different behavior between:
```javascript
class Foo {
#foo = 'foo';doSomething(): void {
console.log(this.#foo);
}
}class Bar extends Foo {}
new Foo().doSomething(); // Works
new Bar().doSomething(); // Works
Object.create(new Foo()).doSomething(); // ERROR: Cannot read private member.
```In my mind, they should create basically the same prototype inheritance. Why does `Object.create` fail?
-
What is the difference between extending a subclass of an object and `Object.create`-ing based on a prototype for the purposes of JS private fields? I'm surprised to get different behavior between:
```javascript
class Foo {
#foo = 'foo';doSomething(): void {
console.log(this.#foo);
}
}class Bar extends Foo {}
new Foo().doSomething(); // Works
new Bar().doSomething(); // Works
Object.create(new Foo()).doSomething(); // ERROR: Cannot read private member.
```In my mind, they should create basically the same prototype inheritance. Why does `Object.create` fail?