- Learn Type:Driven Development
- Yawar Amin Kamon Ayeva
- 200字
- 2021-07-02 14:41:23
Analyzing code for hidden errors
Let's suppose that you have the following JavaScript:
// src/Ch01/Ch01_Demo.js
function makePerson(id, name) { return {id, name}; }
A lot of things can go wrong with the preceding code; they are as follows:
- The caller can pass in nulls or undefined values as arguments
- The caller can pass in unintended types of arguments
- The caller can manipulate the returned person object any way they like, for example, they can add or remove properties
In other words, this code doesn't prevent a number of potential errors. In JavaScript, we have linters, such as ESLint (https://eslint.org/), that check for a lot of possible errors, but you have to remember to find them, enable them, and then work around their limitations. A linter can be helpful in various other ways, such as by pointing out the recommended best practices in a coding style. However, linters in JavaScript are often re-purposed to perform static type checking tasks as well; because they offer so much flexibility and need to be configured (in fact, people usually upload their preferred sets of configuration for different styles of programming), there may be large differences in what exactly gets checked across different codebases.
- HTML5移動Web開發(fā)技術(shù)
- R語言數(shù)據(jù)可視化之美:專業(yè)圖表繪制指南
- Linux命令行與shell腳本編程大全(第4版)
- Mastering JBoss Enterprise Application Platform 7
- Access 2010中文版項目教程
- 智能搜索和推薦系統(tǒng):原理、算法與應(yīng)用
- Hadoop大數(shù)據(jù)分析技術(shù)
- Android應(yīng)用開發(fā)實(shí)戰(zhàn)(第2版)
- PHP 8從入門到精通(視頻教學(xué)版)
- Go語言入門經(jīng)典
- C語言程序設(shè)計與應(yīng)用實(shí)驗(yàn)指導(dǎo)書(第2版)
- Web開發(fā)新體驗(yàn)
- Cloud Development andDeployment with CloudBees
- Unity與C++網(wǎng)絡(luò)游戲開發(fā)實(shí)戰(zhàn):基于VR、AI與分布式架構(gòu)
- 亮劍C#項目開發(fā)案例導(dǎo)航