<<JavaScript Enlightenment>> note

  • <<JavaScript Enlightenment>> pdf下载:https://github.com/robertzhai/ebooks/blob/master/client/JavaScript_Enlightenment.pdf

  • ✴  An object is made up of named properties that store values.

  • ✴  Most everything in JavaScript can act like an object. Complex values are, well, objects andprimitive values can be treated like objects This is why you may hear people say that everythingin JavaScript is an object.

  • ✴  Objects are created by invoking a constructor function with thenewkeyword, or by using ashorthand literal expression.

  • ✴  Constructor functions are objects (Function()objects), thus, in JavaScript, objects createobjects.

  • ✴  JavaScript offers 9 native constructor functions:Object(),Array(),String(),Number(),Boolean(),Function(),Date(),RegExp(),andError(). TheString(),Number(),andBoolean()constructors are dual-purposed in providing a.) primitive values and b.) objectwrappers when needed, so that primitive values can act like objects when so treated.

  • ✴  The valuesnull,undefined,"string",10,true, andfalseare all primitive values, without anobject nature unless treated like an object.

  • ✴  When theObject(),Array(),String(),Number(),Boolean(),Function(),Date(),RegExp(), and Error()constructor functions are invoked using thenewkeyword, an object iscreated that is known as a "complex object" or "reference object".

  • ✴  "string",10,true, andfalse, in their primitive forms, have no object qualities until they are usedas objects; then JavaScript, behind the scenes, creates temporary wrapper objects so that suchvalues can act like objects.


  • ✴  Primitive values are stored by value, and when copied, are literally copied. Complex objectvalues, on the other hand, are stored by reference, and when copied, are copied by reference.

  • ✴  Primitive values are equal to other primitive values when their values are equal, whereas complexobjects are equal only when they reference the same value. That is: a complex value is equal toanother complex value when they both refer to the same object.

  • ✴  Due to the nature of complex objects and references, JavaScript objects have dynamicproperties.

  • ✴  JavaScript is mutable, which means that native objects and user-defined object properties can bemanipulated at any time.

  • ✴  Getting/setting/updating an objectʼs properties is done by using dot notation or bracket notation.Bracket notion is convenient when the name of the object property being manipulated is in theform of an expression (e.gArray['prototype']['join'].apply()).

  • ✴  When referencing object properties, a lookup chain is used to first look at the object that wasreferenced for the property; if the property is not there, the property is looked for on theconstructor functionʼs prototype property. If itʼs not found there, because the prototype holds anobject value and the value is created from theObject()constructor, the property is looked for ontheObject()constructorʼs prototype property (Object.prototype). If the property is not foundthere, then the property is determined to be undefined.

  • ✴  The Prototype lookup chain is how inheritance (a.k.a prototypal inheritance) was design to beaccomplished in JavaScript.

  • ✴  Because of the object property lookup chain (aka prototypal inheritance), all objects inherit fromObject()simply because the prototype property is, itself, anObject()object.

  • ✴  JavaScript functions are first-class citizens: functions are objects with properties and values.

  • ✴  Thethiskeyword, when used inside a function, is a generic way to reference the object

    containing the function.

  • ✴  The value ofthisis determined during runtime based on the context in which the function iscalled.

  • ✴  Used in the global scope, thethiskeyword refers to the global object.

  • ✴  JavaScript uses functions as a way to create a unique scope.

  • ✴  JavaScript provides the global scope, and itʼs in this scope that all JavaScript code exists.

  • ✴  Functions (specifically, encapsulated functions) create a scope chain for resolving variable

    lookups.

  • ✴  The scope chain is set up based on the way code is written, not necessarily by the context inwhich a function is invoked. This permits a function to have access to the scope in which it wasoriginally written, even if the function is called from a different context. This result is known as aclosure.

  • ✴  Function expressions and variables declared inside a function without usingvarbecome globalproperties. However, function statements inside of a function scope remain defined in the scopein which they are written.

  • ✴  Functions and variables declared (withoutvar) in the global scope become properties of theglobal object.

  • ✴  Functions and variables declared (withvar) in the global scope become global variables. 



作者推荐book:
  • ✴  JavaScript: The Good Parts, by Douglas Crockford

  • ✴  JavaScript Patterns, by Stoyan Stefanov

  • ✴  Object-Oriented JavaScript, by Stoyan Stefanov

  • ✴  Professional JavaScript for Web Developers, by Nicholas C. Zakas

  • ✴  High Performance JavaScript,by Nicholas C. Zakas 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值