Zoid is a JavaScript library for simple arithmetic operations. The project has been around for a few years and has a sole maintainer, who works on it in her free time.
Here are a couple of issues picked out of the issue tracker - one from a couple of years ago and one very recent, presented without comment.
Issue #37 - clicking button does not add 1
Oh yeh sorry.
add_handlers: function() {
document.getElementById('add_one').onclick = function() {
this.current_count = zoid.add(this.current_count, 1);
}
},
I do that and then just nothing happens. The counter doesn’t go up. Please help!
Oh ok I think I see the issue. When you reference this.current_count
inside the onclick handler, the value of “this”
will be bound to the element that was clicked, rather than the outer object.
So you can either use an arrow function or bind the outer this
to another name, e.g.
const that = this;
and then use that.current_count
in your click handler.
Okay so I am not sure if this is right but I tried arrow functions and everything seems to be broken right now and I’m not sure what’s up:
add_handlers: function() => {
document.getElementById('add_one').onclick = function() => {
this.current_count = zoid.add(this.current_count, 1);
}
},
function
keyword if you are using arrow functions. That’s a syntax error right now. See the
MDN docs for the
correct syntax.
Ok so I am trying to figure out Babel but running into more problems. It kept talking about “NPM” which is totally alien to me but eventually I found a regular script to download (https://github.com/babel/babel-standalone) and now my HTML page looks like this:
<script src="javascripts/babel.js"></script>
<script type="text/babel" src="javascripts/my_scripts.js">
So this seems to fix the IE problem but this is crazy it’s like 2MB bigger now and makes the website really slow. Is that normal?
So the usual way to do it is to use Node and npm to install Babel and then you just use Babel only on your computer to transpile the script. Then you use the transpiled script in your website and you don’t need to load that huge babel.js file into your website anymore.
To be honest this is kinda getting out of the scope of this issue tracker, which is really just for bugs relating to Zoid. Maybe you can try some forums or StackOverflow?
Ok yeah, sorry to waste your time man, but just one more thing. Ive managed to get node and npm installed but when I try to run “npm run build” like it says in the docs I get this error :
npm ERR! missing script: build
I cannot figure out what it means. My script is called “my_scripts.js”, not “build”!
package.json
file. Follow the instructions on the Babel
website.
Thanks. I added the “build” script to the package.json file but now I get this error:
Module parse failed: /Users/Hecter/learning_js/food_counter/my_scripts.js Unexpected token (45:57)
You may need an appropriate loader to handle this file type.`
I feel like I am a bit out of my depth here with all this npn Babel stuff… Could I upload my whole code somewhere and you take a look? Might be faster!!
So I’ve been trying to upload my code to my account on here but I think I need to use git rather than just upload the files like though ftp or something.
Is that right? How do I use git to upload the files?
Issue #161 - factorial calculation not working
Hi there.
There’s not enough information here to judge whether this is an issue with Zoid, or just an error in your code.
Please take a look at the issue template and actually fill out all the parts requested rather than deleting it all. I’m closing the issue for now, but if you post the filled-out issue template below including code, I’ll consider re-opening.