What is the relationship between how js objects are created and their properties?

here are two examples:

var obj = {};  //
 obj.b = function () {  //
 console.log(1111, this);   //b
    };
 obj.b();
 var obj1 = {   //
 name: "My Object",
 c: function () {
 console.log(222, this);     //object 
        }
    };
 obj1.c();

Why is this?

Mar.09,2021

the first one is also an object, but there is only one b function in the object. You must be mistaken!

var obj = {name: 'My Object'};  //
 obj.b = function () {  //
 console.log(1111, this);   //b
    };
 obj.b();

try


the subject has made a mistake. this are all original objects

var obj = {};  
 obj.b = function () {  
 console.log(1111, this===obj);   //true
    };
 obj.b();
var obj1 = {  
 name: "My Object",
 c: function () {
 console.log(222, this===obj1);     //true
        }
    };

Oh, oh, I know the answer is also upstairs, thank you for not being able to accept your answer

Menu