Basics
Challenges
Classes
Debugging
Events
External Files
Flow Control
Forms
Functions
Html Elements
Installation
Interfaces
Keywords
Modules
Namespaces
Operators
Reference Files
String
Types
This is a good illustration of how one function within a class has visibility to another function using the
this
keyword. Arrow Function likely behave different. A little more research is needed.
namespace ScriptDemo
{
class FunctionExample
{
Counter: number = 0;
CalculateStuff(): void
{
this.Counter++;
this.UpdatePage(this.Counter);
}
UpdatePage(counter: number): void
{
let label: HTMLElement = <HTMLElement>document.getElementById("output");
label.innerHTML = counter.toString();
}
}
window.onload = function ()
{
let functionExample = new FunctionExample();
let button: HTMLButtonElement = <HTMLButtonElement>document.getElementById("UpdateCounterButton");
button.addEventListener("click", () => functionExample.CalculateStuff());
};
}