imtumbleweed / vanilla Goto Github PK
View Code? Open in Web Editor NEWJavaScript library containing useful vanilla classes and functions, originally created for making games and building vanilla UI controls.
JavaScript library containing useful vanilla classes and functions, originally created for making games and building vanilla UI controls.
Can you specify a license (MIT or Apache)?
I was reviewing your article on building a vanilla JS router on Free Code Camp's news, when I ran across this code:
window.onload = event => {
// Add history push() event when boxes are clicked
window["home"].addEventListener("click", event => push(event))
window["about"].addEventListener("click", event => push(event))
window["gallery"].addEventListener("click", event => push(event))
window["contact"].addEventListener("click", event => push(event))
window["help"].addEventListener("click", event => push(event))
}
I was confused, since I'd never seen this access of the window object. About 20 minutes of googling later led me to these two Stack Overflow responses:
https://stackoverflow.com/a/3434388/1420506
https://stackoverflow.com/a/11691401/1420506
Both conclude that using named access on the Window object should probably be avoided in preference to document.getElementById()
. As I understand the reasoning, it is possible or even likely to get name collisions in the global window namespace which will result in unexpected behavior. For example, if you chose an element id which overlapped with an existing/reserved global/window property (IE: windows.closed
or window.event
), your router event would not be attached and would not fire.
I believe this is a bad practice, used without proper explanation in your code, and should not be included in a Free Code Camp article named at coding novices.
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.