104corp / f2e-technote Goto Github PK
View Code? Open in Web Editor NEW讀書心得
讀書心得
17b
this 在function 的時候取決於他是怎麼被『呼叫執行』的
例如:一般function
var a = function() { console.log(this)}
a();
// window
這邊你可以把他想成 window.a() 因此是由window來呼叫a 這個function
這時候this 就會指向window
var b = { a:function(){ console.log(this) }}
b.a();
// b:{ a.....}
其實對照上面就很清楚了,這時候就變成b 在執行這個function 因此很自然的this 就指到了b
而constructor (new) 為何不一樣?因為constructor 他會自己先產生一個空物件,然後讓這個空物件去執行他的constructor函式,做完constructor function 之後再賦值給宣告,如下
var a = function(){ console.log(this)}
var con = new a();
==> {}.a()
==> con = {} // constructor temp object
// con: {}
這段提到匿名函數沒有hoisting 應該不太正確
他還是有hoisting,這牽涉到hoisting 只提昇宣告(var) 不提昇 賦值( initialize)的原理
console.log(func);
var func = function() {
}
// undefined
如果沒有hoisting 的話應該是js error 而不是 undefined
console.log(func);
const func = function(){};
// error
YUI 與 Lab.js 其實已經是作古的script
之後可以忽略這兩個library進行研究喔!
早期的js 書籍都是yahoo 當初實作YUI的那群人所編撰,因此範例都會使用YUI來講,但YUI已經停止維護更新了
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.