Skip to Content
精通模块化JavaScript
book

精通模块化JavaScript

by Nicolás Bevacqua
April 2020
Intermediate to advanced
177 pages
1h 45m
Chinese
Publishing House of Electronics Industry
Content preview from 精通模块化JavaScript
4.3
 像熵一样的状态
95
4.3
 像熵一样的状态
entropy
)可以被定义为对无序性或不可预测性的一种度量。系统中的
熵越大,系统就越无序和不可预测。程序的状态与熵非常类似。不论讨论
的是全局应用状态、用户会话状态,还是给定用户会话下特定组件实例的
状态,当我们尝试理解程序的流程、程序如何到达现在所处的状态、现在
的状态如何决定以及帮助预测流程的执行等问题时,我们在应用中创建的
每一个状态,都是一个需要考虑的新维度。
在这一节,我们将讨论消除和包装状态的方法,还有不可变性。首先,我
们讨论当前状态是由什么组成的。
4.3.1
 复杂的当前状态
状态的问题是,随着应用变大,状态也跟着变大,因此大型应用总是复杂
得令人绝望。这种复杂性存在于整体中,但不一定存在于在单个部分中。
这就是为什么将应用分解为更小的组件后,即使整体复杂性增加,局部复
杂性也可以减少。也就是说,将单个大函数分解为一堆小函数,可能使整
个应用变得更加复杂,因为那些小函数的数量会有原来
10
倍之多。但是,
这样做也让大函数之前的各部分功能现在由小函数覆盖,当我们关注它们
的时候,会变得更简单。如此一来,不需要对整个系统有全面或大范围的
了解,也可以很容易地维护一个大型复杂系统的各个部分。
从本质上说,状态都是可变的。即使变量绑定本身是不可变的,总的来看
状态仍是可变的。一个函数可能每次都会返回不同的对象,我们甚至可以
让这个对象不可变,这样对象自身就不能变化。但是,每次使用这个函数
都会接收一个不同的对象。不同的对象意味着不同的引用,意味着状态作 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

数据驱动力:企业数据分析实战

数据驱动力:企业数据分析实战

Carl Anderson
基于Python的智能文本分析

基于Python的智能文本分析

Benjamin Bengfort, Rebecca Bilbro, Tony Ojeda
Lua游戏AI开发指南

Lua游戏AI开发指南

Posts & Telecom Press, David Young

Publisher Resources

ISBN: 9787121387074