0

everybody, I'm new in Javascript... I know how to incorporate a function into an Object using this format...

var xyz = {
    yearOfBirth: 1963,
    calculateAge: function() {
        this.age = (new Date().getFullYear()) - this.yearOfBirth;
    }
};

***But I need your guidance on this other format...

var abc = new Object();

Thanks!

Dennis Tsoi
  • 1,349
  • 2
  • 11
  • 17

1 Answers1

1

About your question. When a object is defined using a constructor, properties can be defined like so:

var abc = new Object()
abc["yearOfBirth"]=1963

abc["calculateAge"]=function(){
    this.age=(new Date().getFullYear())-this.yearOfBirth;
}

you can also do this:

var abc = new Object()
abc.yearOfBirth=1963

abc.calculateAge=function(){
    this.age=(new Date().getFullYear())-this.yearOfBirth;
}