i created a crypto object as follows:
var crypto = {
encrypt: function(s) {
}
};
crypto.encrypt("cat");
I would get the following error
Uncaught TypeError:
crypto.encrypt
is not a function
var crypt = {
encrypt: function(s) {
}
};
crypt.encrypt("cat");
this would work. I realized that there is already an inbuilt crypto
object so the crypto object i defined was not being recognized.
My understanding is that the variables declared later will shadow variable declared previously.
For example when i create two objects like follows:
var test = {
testing2: function() {
return "there";
}
}
var test = {
testing: function() {
return "hey";
}
}
test.testing2()
and i call test.testing2()
then the similar error is thrown because the second test variable has shadowed the first. So if variable shadowing works with self created variables then why is crypto not being shadowed? Is it the case that the predefined objects are always higher in priority so any self created objects will not shadow the window objects. I appreciate any insights into this. Thanks!