From d7588829729f69ccbe0156bcbdc8aed080cdfb37 Mon Sep 17 00:00:00 2001 From: Hanzhang ma Date: Sun, 23 Jun 2024 23:57:39 +0200 Subject: [PATCH] add NFE --- 6.4NFE/t.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 6.4NFE/t.js diff --git a/6.4NFE/t.js b/6.4NFE/t.js new file mode 100644 index 0000000..a4d1392 --- /dev/null +++ b/6.4NFE/t.js @@ -0,0 +1,44 @@ +function sayHi(){ + console.log("Hi"); + + sayHi.counter++; +} + +console.log(sayHi.name) + +let user = { + sayHi(){ + + }, + + sayBye: function (){ + + } +} + +console.log(user.sayBye.name) +console.log(user.sayHi.name) + +function ask(question, ...handlers){ + let isYes = confirm(question); + + for(let handler of handlers){ + if (handler.length == 0){ + if (isYes) handler(); + }else{ + handler(isYes); + } + } +} + +ask("Question?", () => console.log('You said yes'), result => console.log(result)) + +console.log("the difference between the counter.count and closure is the counter.count can be accessed outside but closure cannot"); + +let sayHi = function func(who){ + console.log(`Hello, ${who}`); +}; + +sayHi("John"); + +