The talk starts from very basic concepts, but evolves to an advanced topic: a codebase free of runtime exception. It gives the programmer a good perspective of all the resources available to fill the language gaps to create a bullet-proof code.
25. Common Mistake #1:
Incorrect references
to this
The 10 Most Common Mistakes
JavaScript Developers Make
by Ryan J. Peterson
26. function Product(name, cost, tax) {
if (!(this instanceof Product)) {
throw new Error("Constructor called as a function")
}
this.name = name
this.cost = cost
this.tax = tax
}
Product("Banana", 2, "%30")
27.
28. const item = new Product("Banana", 2, "%30")
item.price()
this.name = name
this.cost = cost
this.tax = tax
}
price() {
return this.cost *
(1 + this.tax)
}
}
This is Not
a Number™
29.
30.
31. 1. undefined is not a function
2. incorrect this reference
3. wrong use of classes/
constructors
4. cannot read/set any
property of undefined/null
5. silent errors
51. /* @flow */
function crazy() : number | string | Array<null> {
const rand = Math.random()
if (rand > .5) {
return 0
}
if (rand < .5) {
return []
}
return rand.toString()
}
const ops : number | string | Array<null> = crazy()
Type smells!
52. A Type System is,
first and foremost,
a communication
mechanism
Tweet by Sarah Mei
53. A Type System replaces
direct communication
with other humans, when
such communication isn't
practical - large teams,
open source, etc
Tweet by Sarah Mei
56. interface ItemsResponse {
results: string[]
}
http.get<ItemsResponse>('/api/items')
.subscribe(data => {
this.results = data.results
})
It should return a
result property
with an array of
strings
from Angular documentation