我试图了解Javascript方法在后台如何工作。
First I created a variable using var
keyword in the chrome's console and tried to add a method to it:
var name1 = 'SARA';
name1.toLowerCase();
the name1
returns sara
.
After this I tried to do the same thing using let
keyword:
let name2 = 'SARA';
name2.toLowerCase();
And as expected we have sara
again. BUT:
if I try to return name variables like this I get undefined
for name2
which is declared using let
keyword!
let name2 = 'SARA';
window.myname
undefined
How does toLowerCase
method work? if declaring a variable using let
keyword makes it undefined
in the window object, how it still works on this kind of data?!
Are Javascript methods like toLowerCase
attached to window object?
Can we create new methods like toLowerCase
which we can use in our codes?
例如,是否有任何解决方案来创建这样的东西:
var name3 = 'Sara is a pretty girl';
name3.addDotToEnd();
window.name3
'Sara is a pretty girl.'