February 2019
Beginner
694 pages
18h 4m
English
Before we continue with this chapter, let's take a quick look at how TypeScript implements classes in the generated ES3 or ES5 JavaScript through a technique called closures. As we mentioned in Chapter 1, TypeScript – Tools and Framework Options, a closure is a function that refers to independent variables. These variables essentially remember the environment in which they were created. Consider the following JavaScript code:
function TestClosure(value) {
this._value = value;
function printValue() {
console.log(this._value);
}
return printValue;
}
var myClosure = TestClosure(12);
myClosure;
Here, we have a function named TestClosure that takes a single parameter, named value. The body of the function first assigns the ...
Read now
Unlock full access