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
102
4
内部构造
当程序中出现大量中间状态和来回改变数据形态的逻辑时,说明你选择的
数据表达可能不太合适。如果找到了合适的数据结构,你就会发现要使输
入变成想要的输出,其所需的转换、映射与循环都不会很多。下一节我们
将深入介绍数据结构。
4.4
 数据结构为王
数据结构既可以成就一个应用也可以毁灭一个应用,因为围绕数据结构所
做出的设计决策决定了这些结构会如何被访问。考虑下面的代码片段,它
提供了一个博客文章的列表
[{
slug: 'understanding-javascript-async-await',
title: 'Understanding JavaScript's async await',
contents: '...'
}, {
slug: 'pattern-matching-in-ecmascript',
title: 'Pattern Matching in ECMAScript',
contents: '...'
}, ...]
当需要对列表排序或将其中的对象映射为其他表达方式(如
HTML
)时,
采用基于数组的列表就非常合适。不过,如果要寻找不同的元素以便使用、
更新或删除,这种列表就不合适了。数组也让保持元素唯一性变得更加困
难,比如我们希望确保
slug
字段在所有博客文章中是唯一的。在这些情况
下,可以选择基于对象
Map
的方法,如下所示
{
'understanding-javascript-async-await': {
slug: 'understanding-javascript-async-await', ...
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