Skip to main content
added 21 characters in body; edited title
Source Link
Dave Newton
  • 160.5k
  • 27
  • 263
  • 310

Javascrtip Javascript OOP. Methods

Just wondering, having the following simple code:


var object1 = {
    name: function (){
        return 'myName';
    },
    surname: function (){
        return 'mySurname';
    }
};
var object1 = {
    name: function (){
        return 'myName';
    },
    surname: function (){
        return 'mySurname';
    }
};

Why does JS returns function() in this case object1.name ?

Why does JS returns the expected result myName if I call object1.name() ?

Javascrtip OOP. Methods

Just wondering, having the following simple code:


var object1 = {
    name: function (){
        return 'myName';
    },
    surname: function (){
        return 'mySurname';
    }
};

Why does JS returns function() in this case object1.name ?

Why does JS returns the expected result myName if I call object1.name() ?

Javascript OOP Methods

Just wondering, having the following simple code:

var object1 = {
    name: function (){
        return 'myName';
    },
    surname: function (){
        return 'mySurname';
    }
};

Why does JS returns function() in this case object1.name ?

Why does JS returns the expected result myName if I call object1.name() ?

Source Link
Jackie Chan
  • 2.7k
  • 6
  • 36
  • 71

Javascrtip OOP. Methods

Just wondering, having the following simple code:

var object1 = {
    name: function (){
        return 'myName';
    },
    surname: function (){
        return 'mySurname';
    }
};

Why does JS returns function() in this case object1.name ?

Why does JS returns the expected result myName if I call object1.name() ?