en.javascript.info/archive/proto/user.js
Ilya Kantor 03cbee39ae work
2016-08-08 18:34:47 +03:00

16 lines
294 B
JavaScript

```js run
function User(name, birthday) {
let age = calcAge();
function calcAge() {
new Date().getFullYear() - birthday.getFullYear();
}
this.sayHi = function() {
alert(name + ', age:' + age);
};
}
let user = new User("John", new Date(2000,0,1));
user.sayHi(); // John
```