Comments (8)
数据类型:原生与对象
- 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.
原型与原型链
- 原型对象:默认是伴生对象,伴生于构造器函数,是构造器函数自身拥有的原型属性,而这个属性可读也可写
- 原型:几乎所有对象都有原型,包括原型对象也有原型,通过全局唯一原型方法 __proto__ 获取
- 原型链:原型方法 __proto__ 不断向上追溯形成原型链
from learning_list.
解构赋值表达式
let person = {
name: 'l',
sex: 'm'
}, name, sex
// 这是解构赋值表达式,为避免混淆,加上括号
// 否则花括弧部分会被识别为独立表达式,造成 Error: Unexpected token =
({name, sex} = person)
但是,{name, sex} = {name: 'll', sex: 'mm'} 正常使用。。。。。
from learning_list.
this context: the object where the function run
在 JS 中,this 就是 context,非箭头函数在运行时所身处的上下文,这个上下文就是 this,肯定是某一个具体的对象。比如 window 对象,自己创建的 obj 对象,等等。
from learning_list.
generator function generate a iterator called generator
from learning_list.
变量提升
from learning_list.
作用域与闭包
from learning_list.
"falsy" values list:
undefined
null
false
+0
,-0
, andNaN
""
有且仅有这些。
from learning_list.
Related Issues (20)
- 给函数式程序员的 Hack Pipe:我如何学着停止担忧并爱上那顶小帽子 HOT 1
- 一文说透 TypeScript 的增删查改
- 重温 React hook 基本原理
- rust 中消失的三元去了哪里?
- 如何判断类型中是否有必填字段
- automate chrome by script kit
- applescript 踩坑经验
- hammerspoon 添加自定义菜单,执行 shell 脚本
- karabiner multitouch_extension
- 我的 Mac 使用实践总结
- 活久见之 JS 新见闻:return 写不写还是有关键区别的。
- Rust trait vs TypeScript interface
- React Final Form useFormValuesWatch
- data fetch in react
- type safe useParams
- finally, learn how generate struct with builtin function in Zig
- zig code: auto git push, find suitable target branch and open merge url in browser
- bun preloader for test
- depth protection and loose union
- 初步建立起 RSC 的直观体验 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from learning_list.