Suppose an object is declared as follows
var object1 = {
    getName: function() {
        alert(name)
    }
};
Is there a way to alert "object1" from getName?
Suppose an object is declared as follows
var object1 = {
    getName: function() {
        alert(name)
    }
};
Is there a way to alert "object1" from getName?
 
    
     
    
    If you declare an object like object literal then the answer is no, you can't get variable name. You can however declare it using constuctor:
function Obj() {
    this.getName = function() {
        console.log(this.constructor.name);
    }
}
new Obj().getName(); // "Obj"
