Giter VIP home page Giter VIP logo

Comments (8)

xxleyi avatar xxleyi commented on May 23, 2024

数据类型:原生与对象

  • array:带索引属性的对象,不同于 Python 中的 List,也不同于 C 中的 array,C++ 中的 Vector
  • object:对象,内涵及其丰富,不同于 Python 中的 Dict,也不同于常见的 Hash
  • map:map,有序哈希
  • set:set,有序集合

和 Python 类似,引进迭代器,生成器,可迭代,可枚举(Python 中使用不多,JS 比较常见)。

方法也是类似,可迭代的数据类型有默认的迭代器函数,有提供生成器函数的书写语法。

注:在 Python 中好像不关心可迭代和可枚举的区别,反正都是使用 for ... in 语法糖


以上是站在使用者的角度,尤其是与 Python 类比:

  • Object & Map vs dict
  • Set vs set
  • Array vs list

但在 JS 逻辑中,以上四个都是 Object 类型,真正的数据类型分类如下:

Data types

The latest ECMAScript standard defines eight data types:

使用运算符 typeof 可以拿到变量所属的变量类型,同时注意 JS 中有一个语言级别的 bug:typeof null => 'object'

经常使用的小技巧: typeof AnyVariableNotInEnvironment => undefined

Try use objects only when there is logic that operates on individual elements.

from learning_list.

xxleyi avatar xxleyi commented on May 23, 2024

原型与原型链

  • 原型对象:默认是伴生对象,伴生于构造器函数,是构造器函数自身拥有的原型属性,而这个属性可读也可写
  • 原型:几乎所有对象都有原型,包括原型对象也有原型,通过全局唯一原型方法 __proto__ 获取
  • 原型链:原型方法 __proto__ 不断向上追溯形成原型链

from learning_list.

xxleyi avatar xxleyi commented on May 23, 2024

解构赋值表达式

let person = {
  name: 'l',
  sex: 'm'
}, name, sex

// 这是解构赋值表达式,为避免混淆,加上括号
// 否则花括弧部分会被识别为独立表达式,造成 Error: Unexpected token =
({name, sex} = person)

但是,{name, sex} = {name: 'll', sex: 'mm'} 正常使用。。。。。

from learning_list.

xxleyi avatar xxleyi commented on May 23, 2024

this context: the object where the function run

在 JS 中,this 就是 context,非箭头函数在运行时所身处的上下文,这个上下文就是 this,肯定是某一个具体的对象。比如 window 对象,自己创建的 obj 对象,等等。

from learning_list.

xxleyi avatar xxleyi commented on May 23, 2024

generator function generate a iterator called generator

image

from learning_list.

xxleyi avatar xxleyi commented on May 23, 2024

变量提升

#197

from learning_list.

xxleyi avatar xxleyi commented on May 23, 2024

作用域与闭包

#93
#11

from learning_list.

xxleyi avatar xxleyi commented on May 23, 2024

"falsy" values list:

  • undefined
  • null
  • false
  • +0-0, and NaN
  • ""

有且仅有这些。

from learning_list.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.