Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // var john = {
- // firstName: "John",
- // lastName: "Doe",
- // birthYear: 1990,
- // family: ["Jane", "Mike", "Emily"],
- // job: "teacher",
- // isMarried: false,
- // calcAge: function(){
- // // return 2020 - birthYear;
- // // return 2020 - this.birthYear
- // // this.age = 2020 - this.birthYear
- // }
- // };
- // console.log(john)
- // console.log(john.family[0])
- // console.log(john["lastName"])
- // console.log(john.calcAge(1990))
- // console.log(john.calcAge())
- // john.calcAge()
- // console.log(john.age)
- // john.job = 'designer'
- // console.log(john)
- // var jane = new Object();
- // jane.name = 'Jane'
- // jane.birthYear = 1992
- // console.log(jane)
- var User = function(name, job, birthYear) {
- this.name = name;
- this.job = job;
- this.birthYear = birthYear;
- // this.calcAge = function() {
- // console.log(2020 - this.birthYear);
- // };
- };
- User.prototype.calcAge = function(){
- return 2020 - this.birthYear
- }
- // User("John", "teacher", 1990)
- var john = new User("John", "teacher", 1990);
- john.role = 'admin'
- console.log(john);
- var jane = new User("Jane", "designer", 1990);
- console.log(jane)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement