mjavascript / practical-modern-javascript Goto Github PK
View Code? Open in Web Editor NEW🏊 Dive into ES6 and the future of JavaScript
Home Page: https://mjavascript.com
License: Other
🏊 Dive into ES6 and the future of JavaScript
Home Page: https://mjavascript.com
License: Other
There is a code on p. 195 (6.1.3 Schema Validation with Proxies) that isnt working for me.
const validations = new Map()
const validator = {
set(target, key, value) {
if (validations.has(key)) {
return validations[key](value)
}
return Reflect.set(target, key, value)
}
}
I suggest to change return validations[key](value)
to validations(key)(value)
, because of:
Map
object dont support accessing through []
, only through get
method.return
result of validation, we dont actually reach setting value at target[key]
. If we just validate value by direct method call of validations
object, as I suggesting, we throw error in that method if value isnt valid, or bypass this method in case of valid value and reach setting the value in Reflect.set
.I find that there are no instructions for someone to clone the repository and build an epub, pdf or other book format from the source. Is that something that is "common knowledge"? Maybe a small section in the Readme.md would be useful.
It has a miswrite the '+' identifier in the sku: brand + ':' [] make
const getCarProductModel = ({ brand, make, model }) => ({
sku: brand + ':' make + ':' + model,
brand,
make,
model
})
getCarProductModel(car)
See last code examples in this section.
If I get this right, we get a sequence from the shuffleSongs()
just once and iterate this sequence every time in the same order. So we cannot have different order inside each loop like:
// <- ['a', 'b', 'b', 'a', 'a', 'b']
Only these varians are possible:
// <- ['a', 'b', 'a', 'b', 'a', 'b']
// <- ['b', 'a', 'b', 'a', 'b', 'a']
See https://github.com/mjavascript/practical-modern-javascript/blob/master/ch01.asciidoc#fig0102 and the previous code.
Currently, I get this output:
1:12 error Infix operators must be spaced space-infix-ops
3:10 error 'hello' is defined but never used no-unused-vars
3:15 error Missing space before function parentheses space-before-function-paren
3:17 error Missing space before opening brace space-before-blocks
4:17 error Requires a space before '}' block-spacing
4:17 error Closing curly brace should be on the same line as opening curly brace or on the line after the previous block brace-style
6:1 error Expected space(s) after "if" keyword-spacing
6:4 error Unexpected constant condition no-constant-condition
6:10 error Missing space before opening brace space-before-blocks
✖ 9 problems (9 errors, 0 warnings)
7 errors, 0 warnings potentially fixable with the `--fix` option.�
Maybe at least the line about extra semicolon can be deleted from the screenshot as most confusing (there is no semicolon in the code).
Hi. At the end of the 2nd chapter you provide the following piece of code saying:
When the items variable is changed to reference another list of items, we’re in for a world of hurt—the todo API still works with the value items used to have, but items is referencing something else now.
var items = ['a', 'b', 'c']
var todo = checklist(items)
todo.check()
console.log(items)
// <- ['b', 'c']
items = ['d', 'e']
todo.check()
console.log(items)
// <- ['d', 'e'], would be ['c'] if items had been constant
function checklist(items) {
return {
check: () => items.shift()
}
}
IMHO items
and the checklist
function are just forming a closure. So once that todo
var is created and items
is referenced to another thing, it doesn't matter what is done to items
, it's irrelevant to the code.
I'm just a hobbyist so I thought someone should take a look at it.
The "GitHub" link at https://ponyfoo.com/books/practical-modern-javascript/chapters/3#object-spread refers https://github.com/tc39/proposal-promise-finally while it seems it should refer https://github.com/tc39/proposal-object-rest-spread
The section Lexical Scoping https://ponyfoo.com/books/practical-modern-javascript/chapters/2#lexical-scoping-8zsxfqh9
claims that arrow functions don't create closures. It looks like they do. In fact, the code relies on closure of arguments in the evaluation of the returned function. I think this should say "arrow functions don't create their own lexical scope, so arguments is accessed from the closure of the enclosing function".
calc=((a)=>( (b)=>{debugger; return a+b} ))(a=1); calc(2)
It seems there is a conflict between some editions:
Consider the next snippet, where a property named
code
wouldn’t have been as indicative of its contents ascolorCode
could be:
var { metadata: { gender: characterGender } } = character
The scenario we just saw repeats itself frequently, because properties are often named in the context of their host object. While
palette.color.code
is perfectly descriptive,code
on its own could mean a wide variety of things, and aliases such ascolorCode
can help you bring context back into the variable name while still using destructuring.
This section suggests the Spread Operator syntax only works for iterable object literals. In fact, generic Object literal declarations also support spread operator assignment syntax:
"Note that the spread operator isn’t limited to arrays and arguments. The spread operator can be used with any iterable object. Iterable is a protocol in ES6 that allows you to turn any object into something that can be iterated over. We’ll research the iterable protocol in Iteration and Flow Control."
Is there another section where non-iterable Object Literal spread syntax is covered?
In some places you put spaces inside curly braces:
const message = `The sum of ${ input.join(`+`) } is ${ sum }`
but in others you don’t:
const summary = `${units}x ${name} ($${unitPrice}) = $${totalPrice}`
Hey @bevacqua , can I translate this book to brazilian portuguese?
Why I can't buy book? Amazon is the worst choice for ebooks, because there is no way to get and read clean pdf.
Why shall I grant you:
Don't you think it is too much access rights for you? And violate privacy?
Why do you need such information about people?
It would be good to consider collaborating with other platforms such as Manning publishing (as they provide all formats) or PacktPub Publishing.
I suggest it might be a good book about modern Javascript, but the way how you distribute book gives no change to acquaint with it.
hello sir ...
can i translate into indonesian language. so that the people of Indonesia easier to read it .....??
thank you very much for the attention
Line 297 of ch08.asciidoc.txt
:
export count
I think it will cause SyntaxError
too.
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.