r/javascript • • Mar 14 '19

Why you need Prettier in your life if you work in a team

Thumbnail
medium.com
4 Upvotes

r/javascript • • Apr 29 '25

go-go-try: Golang-style error handling for JS/TS

Thumbnail
github.com
0 Upvotes

r/javascript • • Oct 27 '22

What Is Deno and Why You Should Try It

Thumbnail
fusebit.io
1 Upvotes

r/javascript • • Dec 29 '17

help Can i learn JavaScript?

1 Upvotes

Hi, i am 29 and dont know anything about coding. But, i am very willing to learn and work at this. How can i start and what should i do? After learning JS can i work as a frontend developer? Any suggestions?


r/javascript • • Nov 19 '14

Dicks API - Dicks as a service

Thumbnail dicks-api.herokuapp.com
1 Upvotes

r/javascript • • Oct 22 '19

Dead-Simple JavaScript Components w/o the overhead

Thumbnail
medium.com
1 Upvotes

r/javascript • • Mar 20 '15

Forget SASS, it's all about DICSS now

Thumbnail letsgetrandy.github.io
0 Upvotes

r/javascript • • Jun 30 '22

What is Fresh? - Taking a look at a fresh new web framework

Thumbnail
webtips.dev
0 Upvotes

r/javascript • • Jan 08 '11

Underscore.js javascript Library for functional programing

Thumbnail xahlee.blogspot.com
0 Upvotes

r/javascript • • Aug 02 '26

AskJS [AskJS] Building a 2D Game Engine from scratch in pure ES6 Vanilla JS. Here is how I handle SpriteSheets & AnimatedSprites!

28 Upvotes

Hi everyone!

I've been working on BeeEngine 2D, a lightweight HTML5 game engine built with pure Vanilla JS (ES6) and direct Canvas API—no external libraries, no build tools, and zero heavy frameworks.

A lot of modern tools hide sheet slicing behind JSON files, but I wanted a bare-metal, highly efficient approach that gives 100/100 on Lighthouse Performance and instant loading times.

I separated the asset slicing logic from the animation timing logic into two distinct classes:

  1. BeeSpriteSheet: Handles frame dimensions, columns, rows, and coordinate calculations.

  2. BeeAnimatedSprite: Handles frame timing, state, loops, and flipX transformations.

Here is my BeeAnimatedSprite class implementation:

export class BeeAnimatedSprite {
    constructor(spriteSheet, config = {}) {
        this.sheet = spriteSheet;
        this.animations = config.animations || {};
        this.currentAnimName = config.animation || Object.keys(this.animations)[0];


        this.currentFrameIndex = 0;
        this.timer = 0;
        this.flipX = false;
    }


    play(name) {
        if (this.currentAnimName !== name && this.animations[name]) {
            this.currentAnimName = name;
            this.currentFrameIndex = 0;
            this.timer = 0;
        }
    }


    update(dt) {
        const anim = this.animations[this.currentAnimName];
        if (!anim || !anim.frames || anim.frames.length === 0) return;


        const fps = anim.fps || 8;
        const frameDuration = 1 / fps;


        this.timer += dt;


        if (this.timer >= frameDuration) {
            this.timer -= frameDuration;


            if (anim.loop) {
                this.currentFrameIndex = (this.currentFrameIndex + 1) % anim.frames.length;
            } else {
                this.currentFrameIndex = Math.min(this.currentFrameIndex + 1, anim.frames.length - 1);
            }
        }
    }


    draw(ctx, x, y, options = {}) {
        const anim = this.animations[this.currentAnimName];
        if (!anim) return;


        const frameToDraw = anim.frames[this.currentFrameIndex];
        const width = options.width || this.sheet.frameWidth;
        const height = options.height || this.sheet.frameHeight;


        ctx.save(); 


        if (this.flipX) {
            // 2. Sposta l'origine al bordo destro dell'immagine e specchia l'asse X
            ctx.translate(x + width, y);
            ctx.scale(-1, 1);


            
            this.sheet.drawFrame(ctx, frameToDraw, 0, 0, width, height);
        } else {
            // Disegno normale senza specchio
            this.sheet.drawFrame(ctx, frameToDraw, x, y, width, height);
        }


        ctx.restore(); 
    }
}

And here is how
 I implemented it inside main.js:


const megaSheetImg = gioco.getAsset('spritesheet_totale');


        
        const frameW = 128;
        const frameH = 128;


        const apeSheet = new BeeSpriteSheet(megaSheetImg, frameW, frameH, {
            col: 3, 
            row: 3, 
            framesPerRow: 1, 
            frameCount: 2
        });


        this.giocatore.sprite = new BeeAnimatedSprite(apeSheet, {
            animation: "fly",
            animations: {
                fly: { frames: [0, 1], fps: 4, loop: true }
            }
        });

Let me know what you think, bearing in mind that this particular combination is super quick to put together.


r/javascript • • Aug 16 '25

Beyond Booleans

Thumbnail
overreacted.io
0 Upvotes

r/javascript • • Feb 23 '13

Common JavaScript "Gotchas"

Thumbnail
github.com
16 Upvotes

r/javascript • • Nov 01 '24

AskJS [AskJS] Which JS is best for backend development and why?

3 Upvotes

I was at my co-working space and met some Devs that do mobile app development. I assumed it would be with swift or something else. They told me that they use JS and wrap it or use a pipeline.

I am a python backend developer and was curious which JS is used for backend development for web apps and mobile apps. I'm thinking about learning something new to open up career paths.


r/javascript • • Apr 04 '24

Building a Next.js application using Clerk for Authentication, and Drizzle ORM with Postgres for Storage

Thumbnail
neon.tech
3 Upvotes

r/javascript • • Nov 18 '13

Real-time live search of whole Wikipedia in less than 20 lines of JavaScript

Thumbnail liveweave.com
3 Upvotes

r/javascript • • Aug 27 '15

The Evil Side of JavaScript: Server-Side JavaScript Injection

Thumbnail blog.nvisium.com
3 Upvotes

r/javascript • • Jul 20 '26

Your Recursion Is Lying to You

Thumbnail
blog.gaborkoos.com
0 Upvotes

r/javascript • • Aug 12 '25

The Heart Breaking Inadequacy Of AbortController

Thumbnail
frontside.com
0 Upvotes

This blog post says that AbortController is a standard but it's rarely used. Do you agree? Do you find it lacking like the blog post suggests?


r/javascript • • Feb 27 '14

total.js - a node.js web framework and its benefits...

Thumbnail
totaljs.com
8 Upvotes

r/javascript • • Mar 28 '14

console.loge - Doge for your browser

Thumbnail zachinglis.com
19 Upvotes

r/javascript • • May 02 '10

31 jQuery Snippets That Will Help Make You A JavaScript Pro

Thumbnail addyosmani.com
5 Upvotes

r/javascript • • Oct 24 '16

help The only thing I hate about const ...

7 Upvotes

... is that it is 5 chars long.

For some reason, let with its 3 chars, looks more elegant.


r/javascript • • Aug 28 '25

AskJS [AskJS] Is using libraries okay?

0 Upvotes

Hey, I'm a beginner in frontend development and I'm unsure when I should code something from scratch and when I should use ready-made libraries. For example, if I want to create a fade-in effect – should I write it myself in CSS/JS, or use something like AOS? Or if I want to make a slider – is it better to code it from scratch or use something like Swiper.js?


r/javascript • • Mar 26 '16

You Have Ruined Build Systems

Thumbnail you-have-ruined-build-systems.surge.sh
0 Upvotes