Skip to main content
100%

Gist 4b6077fe737b33df1934b8eb4bc57c79

✓ Published0🌍 Public
PPeleke
Last edited May 2, 2016
Created on May 2, 2016

This example demonstrates the behavior of getters in a TypeScript class, showing how a getter can return a function that logs a user’s name to the console. It defines a `User` class with private `name` and `email` fields, and a `speak` getter returns an inner function that accesses the instance’s name. The code uses TypeScript’s class syntax and type annotations, and the sample instantiates a `User`, calls `speak()`, and attempts to override the getter on the prototype, which throws a `TypeError`. The illustration focuses on prototypal getter semantics in a scripting context.

AI-generated description

Similar vizzes