crop_rotate
Run
<!DOCTYPE html> <html> <body> <h2>JavaScript Class Method</h2> <p>How to define and use a Class method.</p> <p id="demo"></p> <script> class Car { constructor(name, year) { this.name = name; this.year = year; } age() { let date = new Date(); return date.getFullYear() - this.year; } } let myCar = new Car("Ford", 2014); document.getElementById("demo").innerHTML = "My car is " + myCar.age() + " years old."; </script> </body> </html>
PCFET0NUWVBFIGh0bWw+DQo8aHRtbD4NCjxib2R5Pg0KDQo8aDI+SmF2YVNjcmlwdCBDbGFzcyBNZXRob2Q8L2gyPg0KDQo8cD5Ib3cgdG8gZGVmaW5lIGFuZCB1c2UgYSBDbGFzcyBtZXRob2QuPC9wPg0KDQo8cCBpZD0iZGVtbyI+PC9wPg0KDQo8c2NyaXB0Pg0KY2xhc3MgQ2FyIHsNCiAgY29uc3RydWN0b3IobmFtZSwgeWVhcikgew0KICAgIHRoaXMubmFtZSA9IG5hbWU7DQogICAgdGhpcy55ZWFyID0geWVhcjsNCg0KICB9DQogIGFnZSgpIHsNCiAgICBsZXQgZGF0ZSA9IG5ldyBEYXRlKCk7DQogICAgcmV0dXJuIGRhdGUuZ2V0RnVsbFllYXIoKSAtIHRoaXMueWVhcjsNCiAgfQ0KfQ0KDQpsZXQgbXlDYXIgPSBuZXcgQ2FyKCJGb3JkIiwgMjAxNCk7DQpkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgiZGVtbyIpLmlubmVySFRNTCA9DQoiTXkgY2FyIGlzICIgKyBteUNhci5hZ2UoKSArICIgeWVhcnMgb2xkLiI7DQo8L3NjcmlwdD4NCg0KPC9ib2R5Pg0KPC9odG1sPg==