# 筆記_javascript基礎攻略 this ---- ###### tags: `javascript` [淺談 JavaScript 頭號難題 this:絕對不完整,但保證好懂](https://blog.techbridge.cc/2019/02/23/javascript-this/#post-comment-wrapper) [學好 this 前,先搞清楚 this 做什麼](https://ithelp.ithome.com.tw/articles/10244942) ---- 心得:如果是跳用一個物件的話, this就是以物件為主, 如果是叫用一個function的話 function中的this是已全域為主 >> **javascript得function 有多種寫法 >> 也就是一級函式的特性** >> - 將函式指定到一個變數 >> - 函式可作為參數來傳遞 >> - 函式也可以被回傳(return) >> - 函式也是物件的物件(傳參考特性、具有屬性) 我答錯的題目: ```javascript= var value = 1; var foo = { value: 2, bar: function () { return this.value; } } //範例1 console.log(foo.bar()); //範例2 console.log((foo.bar)()); //範例3 console.log((foo.bar = foo.bar)()); //範例4 console.log((false || foo.bar)()); //範例5 console.log((foo.bar, foo.bar)()); ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up