TypeScript example
TypeScript example
HTML
<div id="foobar">
<h2>Foo</h2>
<button type="button">Bar</button>
</div>
TypeScript
$(() => {
var foo = new Bar($("#foobar"));
})
class Bar {
private view: JQuery;
private button: JQuery;
constructor(view: JQuery) {
const self = this;
// Fields
self.view = view;
self.button = view.find("button");
// Events
self.button.click(() => { self.buttonClick() });
}
private buttonClick() {
this.view.find("h2").css("background-color", "red");
}
}