If We have
var randomname = {};
randomname.attribute = \'something\';
function randomname(){
alert(randomname.attribute);
}
randomname();
Your function randomname()
is redefining the randomname
identifier, thus losing your reference to the object you constructed earlier. It may look more clear like this:
var randomname = {};
randomname.attribute = 'something';
var randomname = function () {
alert(randomname.attribute);
};
randomname();
It is like doing:
var a = 5;
var a = [20, 30];
console.log(a); // returns [20, 30]