Skip to content

Commit

Permalink
episode for function scope
Browse files Browse the repository at this point in the history
  • Loading branch information
unlimitedcodeG committed Apr 9, 2021
0 parents commit bd49916
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
15 changes: 15 additions & 0 deletions episode1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 作用域对接

function foo(a) {
var b = 2;
// some code
function bar() {
// ..
}
// more code
var c = 3;
}

bar()

console.log(a, b, c);
28 changes: 28 additions & 0 deletions episode2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function doSomething(a) {
b = a + doSomethingElse(a * 2)

console.log(b * 3);
}

function doSomethingElse(a) {
return a - 1;
}

var b;

doSomething(2);


// more reesonable
function doSomething(a) {
function doSomethingElse(a) {
return a - 1;
}

var b;
b = a + doSomethingElse(a * 2);
console.log(b * 3);
}

doSomething(2)

22 changes: 22 additions & 0 deletions episode3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var MyReallyCoolLibrary = {
awesome: "stuff",
doSomething: function () {

},
doAnotherThing: function () {

}
}

console.log(MyReallyCoolLibrary.awesome)
console.log(MyReallyCoolLibrary.doSomething)
console.log(MyReallyCoolLibrary.doAnotherThing)


var a = 2;
function foo() {
var a = 3;
console.log(a);
}
console.log(foo());
console.log(a);

0 comments on commit bd49916

Please sign in to comment.