js作用域

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>js作用域</title>
</head>
<body>
<!--在py中:模块,函数,类有自己的作用域-->
<script>
c='beijing';
f=function(){
var c='shanghai';

function inner(){
console.log('456'+c);
}
return inner;

};

f()();
function bar(){
console.log('123'+c)}
f=function(){
c='shanghai';
return bar;
};
f()()
//运行结果;456shanghai
// 123shanghai

</script>

</body>
</html>
posted @ 2020-02-08 14:56  Stary_tx  阅读(213)  评论(0编辑  收藏  举报