legend80s / blog Goto Github PK
View Code? Open in Web Editor NEWBlog
Blog
谷歌决定放弃 Chrome 浏览器中“blacklist(黑名单)“、“whitelist(白名单)”的用法,后续使用“blocklist”和“allowlist”来替代它们。
本文仅代表个人观点。
master slave 这些词语对于遭受过贩卖和奴役的种族或人群来说每一次阅读都是对其心灵的深层次打击,会让其联想到祖辈受过的奴役之苦。而黑白名单 whitelist blacklist 会让人下意识将“白好黑坏”联系到一起,相比 master slave 而言,其直观的心理暗示更让其具备种族优越性的负面教育和挑唆性。
Google、GitHub 等都在替换种族歧视单词的行动中,虽然国内程序员在使用 whitelist / blacklist 和 master / slave 等单词的时候不会潜意识将其和种族歧视联想到一起。
微软、Github 已表示正在火速下架所有相关词汇编程词汇,把 master 换成main(主要的),slave 换成secondary(次要的)。
下架公司或组织:
master slave 可代替单词,来自网络和 ietf
whitelist blacklist 可代替单词,来自网络和 ietf
大家根据代码上下文选择其最合适的组合即可。
希望小小的声音能带来一些微小的变化,让这个世界变得美好一些
先抛出结论:lodash 世界的 parseInt 是 map 安全的。
前端界著名的 parseInt bug:
['6', '08', '10'].map(parseInt);
// [6, NaN, 2]
为何用 lodash 的 parseInt 却是安全的,而且官方特意给出了示例
_.map(['6', '08', '10'], _.parseInt);
// => [6, 8, 10]
最近在做数组的 trim 操作,原本写法:
['001100', '110011'].map(val => _.trim(val))
但转念一想何不这么写,更简洁:
['001100', '110011'].map(_.trim)
完事后走路的途中突然想到,trim 有第二个参数,会当做 trim 的目标字符,即:
_.trim('110011', '1')
// => '000'
那么,结合 map 不是有 bug 吗,下标将会被当做 trim 的目标被删除掉,这是万万不可的,即:
['001100', '110011'].map(_.trim)
// => ['11', '00']
但实际上返回正确,仍然是 ["001100", "110011"]
!
查看 lodash 源码发现有第三个秘密参数 guard,这是一个安全参数,当 truthy 则会省略第二个参数,故 _.trim
是 map 安全的。
官方文档并未有第三个参数的说明,因为:
The
guard
param is not intended for public use an is part of allowing it to work in_.map
and others as an iteratee.
大胆猜测 parseInt 也有第三个安全参数,果不其然。
lodash 的 trim 和 parseInt 能够被安全的当做 map 的处理函数,甚至一系列将会被 map 消费的函数都被 lodash 设计得很安全。
lodash 很强大,解决了原生 js 诸多痼疾 👍。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.