apress / essential-typescript Goto Github PK
View Code? Open in Web Editor NEWSource Code for 'Essential TypeScript' by Adam Freeman
License: Other
Source Code for 'Essential TypeScript' by Adam Freeman
License: Other
Object.setPrototypeOf() has problems, avoid it, instead use Object.create
Replace:
Object.setPrototypeOf(TaxedProduct.prototype,Product.prototype); with
TaxedProduct.prototype = Object.create(Product.prototype)
Object.defineProperty(TaxedProduct.prototype,"constructor",{enumerable:false,value:TaxedProduct)
Steps to reproduce:
One possible solution:
function promptComplete() : void {
...
collection.getTodoItems(true).forEach(item =>
(!showCompleted && item.complete) ||
collection.markComplete(item.id, completedTasks.find(id => id === item.id) != undefined))
...
}
The first six types in the table are the JavaScript primitive data types. The primitive types are always available, and every value in a JavaScript application either is a primitive type itself or is composed from primitive types. The sixth type is object and is used to represent objects.
Should be the seventh type
function sumPrices (...numbers {
return numbers.reduce(function(total, val) {
return total + (Number.isNaN(Number(val))? 0 : Number(val))
}**, 0**)
function sumPrices (...numbers {
return numbers.reduce((total, val) =>
total + (Number.isNaN(Number(val))? 0 : Number(val)) /* **, 0** */)
function sumPrices(...numbers){
return numbers.reduce(function(total,value){
return total + (Number.isNaN(Number(val)) ? 0 : Number(val));
}, 0);
}
The book say "To ensure the function produce a useful sum of its parameter values, however they are received......
sumPrices(100,200,true)
return 301 because Number(true) is 1
and there are other edge cases (as Infinity for example)
I found maybe there is a typo of add function in chapter 13.
add(...newItems: T[]): void {
this.items.push(...newItems);
}
should be ???
add(newItems: T[]): void {
this.items.push(...newItems);
}
With the spread syntax in the argument, It will be
col.add([{ name: 'prod1', price: 10 }, {name: 'prod2', price: 20}])
col.add([{ name: 'prod3', price: 30 }, {name: 'prod4', price: 40}])
// the result of items
[
[{
{ name: 'prod1', price: 10 },
{name: 'prod2', price: 20}
}],
[{
{ name: 'prod3', price: 30 },
{name: 'prod4', price: 40}
}]
]
Is it designated?
export function applyDiscount(product, discount = 5) {
product.price = product.price - 5; // <- should be ** product.price - discount **
}
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.