Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
down with slavery
Dec 23, 2013
STOP QUOTING MY POSTS SO PEOPLE THAT AREN'T IDIOTS DON'T HAVE TO READ MY FUCKING TERRIBLE OPINIONS THANKS
Ultimately I would still avoid for/in

There's a few other options available if you really hate traditional for loops...

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
http://underscorejs.org/#each

etc.

But honestly, you should just get used to them because they really aren't that bad.

Adbot
ADBOT LOVES YOU

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Dominoes posted:

Looking for thoughts on 'for in' loops in javascript, and this Stack Overlow question on the topic. The accepted answer is that
JavaScript code:
for (var i in myArray) {
    var item = myArray[i]
}
is bad because 1: A libary you loaded might have messed with the array class and 2: you might create an array with only some values filled in.

The way I'm looking at it, this:

JavaScript code:
for (var i=0; i < myArray.length; i++) {
    var item = myArray[i]
}
is enough of an eyesore that it's worth using the cleaner syntax. I have no intention of breaking the array class or defining an array with missing values.

the order of a for...in loop is also undefined in the standard. it's implementation specific what order the loop executes.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
If you have an array and not an object, just use forEach.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
ES6 has a for (var i of myArray) that works as expected.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

The more expensive part is usually tracking enumeration state, including prototype traversal and duplicate suppression; there are tricks that make string-of-int cheap. It'll likely be slower in a microbenchmark, but I doubt it'll show up in anything real.

The bigger issue is that for-in isn't guaranteed to be in index order (though practically anything later than IE8 will, I *think*) and as a lesser concern if the array has additional properties on it they'll show up as well.

neurotech
Apr 22, 2004

Deep in my dreams and I still hear her callin'
If you're alone, I'll come home.

I'm currently reflecting on a solution to my first real challenge in a new project I'm working on.

I have an API endpoint that is spitting out a JSON blob which changes every 5 minutes. I want to build a simple front-end that does the following:

  • Polls the feed every 5 minutes and parses it
  • Traverses the parsed results and binds the various keys to various HTML elements
  • Updates said HTML elements with the relevant values associated with each key
  • Animates the changes in some sort of interesting way

My current plan is to use jQuery to poll the whole feed with .getJSON() and .setInterval(), then perform a whole bunch of chained jQuery methods on the various HTML elements.

Can anyone recommend a better way to do this?

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker
Nope, that's pretty much it. :)

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
If it's a simple page and unlikely to change, that could be good enough. Otherwise you might want to check out some framework that automates some of that.

Tres Burritos
Sep 3, 2009

neurotech posted:

I'm currently reflecting on a solution to my first real challenge in a new project I'm working on.

I have an API endpoint that is spitting out a JSON blob which changes every 5 minutes. I want to build a simple front-end that does the following:

  • Polls the feed every 5 minutes and parses it
  • Traverses the parsed results and binds the various keys to various HTML elements
  • Updates said HTML elements with the relevant values associated with each key
  • Animates the changes in some sort of interesting way

My current plan is to use jQuery to poll the whole feed with .getJSON() and .setInterval(), then perform a whole bunch of chained jQuery methods on the various HTML elements.

Can anyone recommend a better way to do this?

Maybe use websockets for this bit? If this is a "for fun" project it might be a neat technology to try out. It might eliminate the getJSON and setInterval parts of your code.

ninjaEdit: actually, mdn says

mdn posted:

WebSockets is an advanced technology that makes it possible to open an interactive communication session between the user's browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.

Which sounds like what you're trying to do?

MrMoo
Sep 14, 2000

Server sent events would be nicer for unidirectional communication, but JSON over XHR is the most convenient.

Miskatonic U.
Aug 13, 2008

Do you read Sutter Cane?
Anyone else headed to JSConf this week?

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



I have a problem that I've been thinking of and I want to know the best way to solve it using good javascript.

Let's say you have objects A, B, and C, and they have a hierarchichal relationship like so:

A has A list of B's
B has A list of C's

code:

A = {
    list: [
        <B> = {
            [
            <C>,
            <C>,
            <C>,
            <C>,
            <C>
            ],
        },
        <B> = {
            [
            <C>,
            <C>,
            <C>,
            <C>,
            <C>
            ],
        },
        <B> = {
            [
            <C>,
            <C>,
            <C>,
            <C>,
            <C>
            ],
        }
    ]
}

Creating an A relies on the list of B's to be populated and creating a B relies on the list of C's to be populated.

If creating B and C was sync then we just have to imperatively create each object and call the callback at the end.

But what if creating B and C is async? Then how do we create an A and run operations when all the B's are done when the callback functions to do the asynchronous operations will be created and control flow will immediately return to the calling function?

We can't just pass a callback to B since the callback would be called multiple times (unless we implement a control to only call the callback when the last B is called which is what I've done so far), unless we change up the entire construction of the flow of this process to have the callbacks able to be called multiple times.

We could use something like the async or promises modules in Node but what is the best way of doing this without extra modules, unless we just create those modules ourselves and use them basically?

A basic synchronous version would be like so:

code:
create a
    for all potential to create b
        create b
        for all potential to create c
            b.list += c
    a.list += b
return a

Raskolnikov2089
Nov 3, 2006

Schizzy to the matic
More of a meta-question here. I've made my first forays into Git, and I love it.

However I don't see the need for using the Git shell when the windows GUI suits my purposes just fine (javascript/php).

Am I missing out on something important ignoring the shell for now? I assume I'll need to use it when I get to Ruby, but for now it doesn't seem helpful.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Raskolnikov2089 posted:

More of a meta-question here. I've made my first forays into Git, and I love it.

However I don't see the need for using the Git shell when the windows GUI suits my purposes just fine (javascript/php).

Am I missing out on something important ignoring the shell for now? I assume I'll need to use it when I get to Ruby, but for now it doesn't seem helpful.

You'll probably be fine as long as you only need basic committing, pulling, pushing, diffing and merging. If you're using it in a one-man project, you won't necessarily even ever need to use the console.

Wheany fucked around with this message at 20:45 on May 27, 2014

Skiant
Mar 10, 2013
Re: git GUI clients for Windows or Mac, you can grab Sourcetree by Atlassian because it's awesome.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

piratepilates posted:

But what if creating B and C is async? Then how do we create an A and run operations when all the B's are done when the callback functions to do the asynchronous operations will be created and control flow will immediately return to the calling function?

We can't just pass a callback to B since the callback would be called multiple times (unless we implement a control to only call the callback when the last B is called which is what I've done so far), unless we change up the entire construction of the flow of this process to have the callbacks able to be called multiple times.

That's basically what you do. You're basically going to do the loops recursively, instead of iteratively.

A synchronous recursive version looks roughly like:
JavaScript code:
function addAnA() {
    var newA = new A();

    function addB() {
        var newB = new B();
        newA.append(newB);

        function addC() {
            var newC = new C();
            newB.append(newC);
            if (moreCs) {
                addC();
            }
        }

        addC();

        if (moreBs) {
            addB();
        }
    }

    addB();
    list.append(newA);
}
Making it async means deferring the make-more-or-"return" decision into the fetch's callback, and making the continuation (code after the "return") explicit:

code:
function addAnA() {
    var newA = new A();

    function addBOrContinue(data, completion) {
        var newB = new B();
        newA.append(newB);

        function addCOrContinue(data, completion) {
            var newC = new C();
            newB.append(newC);

            if (moreCs) {
                getC(addCOrContinue, completion); /* get the next one */
            } else {
                completion(); /* done with the Cs */
            }
        }

        if (moreBs) {
            getB(addBOrContinue, completion);
        } else {
            completion();
        }
    }

    function addAToList() {
        list.append(newA);
    }

    getB(addBOrContinue, addAToList);
}
Edit: it sounds like you might already be doing this, so apologies if so. I'll leave it in case it's useful to someone else regardless, plus who wants to waste that typing?

Subjunctive fucked around with this message at 17:54 on May 27, 2014

0zzyRocks
Jul 10, 2001

Lord of the broken bong

Skiant posted:

Re: git GUI clients for Windows or Mac, you can grab Sourcetree by Atlassian because it's awesome.

Just wanted to re-iterate this - it's a great program and really should be all you need. Integrates well with already installed versions of Git, and has one-click buttons for initiating Git Workflow (and using its various functionality) all without needing to know the console commands. They do help though, especially for more involved operations like submodules.

neurotech
Apr 22, 2004

Deep in my dreams and I still hear her callin'
If you're alone, I'll come home.

quote:

A bunch of useful feedback

Thanks for the responses everyone. I tooled around with socket.io a few months back and it seemed promising. I think I'll spend my saturday trying it out.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

neurotech posted:

I'm currently reflecting on a solution to my first real challenge in a new project I'm working on.

I have an API endpoint that is spitting out a JSON blob which changes every 5 minutes. I want to build a simple front-end that does the following:

  • Polls the feed every 5 minutes and parses it
  • Traverses the parsed results and binds the various keys to various HTML elements
  • Updates said HTML elements with the relevant values associated with each key
  • Animates the changes in some sort of interesting way

My current plan is to use jQuery to poll the whole feed with .getJSON() and .setInterval(), then perform a whole bunch of chained jQuery methods on the various HTML elements.

Can anyone recommend a better way to do this?
Depending on exactly what you're trying to animate, D3.js might be a better option than jQuery since it's really built for exactly this type of dynamism up front. If you just need basic transitions for regular HTML elements though, Transit sounds like what you want for animation.

MrMoo
Sep 14, 2000

That's quite nice, a jQuery layer replicating web animations. Wonder what the performance is like at larger scale with the chaining mechanism. Using RAF tends to work better than CSS transitions though if you want 60fps.

pepito sanchez
Apr 3, 2004
I'm not mexican
Hi. I'm an IT student working on his first programming project. It's all JQuery and JS. Unlike most students I don't have a partner, so I'm having a specially hard time working this out, specially now at the beginning.

It's a simple game of Simon, where two players play against each other. They provide all of the graphics, we simply have to code in a game where two players play against each other, matching a random sequence of colors.

My problem is getting the very first part down. This is mostly a skeleton for what's going to be a game.

I'm trying to get the player names in the form to validate, but for some reason it doesn't even check whether the name is too long or has the special characters I've specified. Yes, the game is in spanish, and my code is mostly not.

I'm just trying to get the names to validate correctly for now. How is my logic wrong?

code:
var illegalChar = ["@", "#", "$", "%", "&", "(", ")"];
var player1 = [];
var player2 = [];
var gameSession = false;


$(init);

function init() {
    $("#comenzarJuego").click(submit);
}

function submit() {
    if(subCheck() === true) {
  gameStart();
    } else {
        $("#nombre1").focus();
    }
}

function subCheck() {
    var check = true;
    player1.name = $("#nombre1").val();
    player2.name = $("#nombre2").val();
    if(player1.name.length > 10) {
        $("#nombre1").html("Su nombre no puede ser mas que 10 caracteres!");
        check = false;
    }
        else if(player2.name.length > 10) {
        $("#nombre2").html("Su nombre no puede ser mas que 10 caracteres!");
        check = false;
    }
    for (i = 0; i < illegalChar.length; i++){
        if(player1.name.indexOf(illegalChar[i]) > -1) {
                    $("#nombre1").html("Esta usando caracteres ilegales!");
            check = false;
        }
    
}
    for (i = 0; i < illegalChar.length; i++){
        if(player2.name.indexOf(illegalChar[i]) > -1) {
                    $("#nombre2").html("Esta usando caracteres ilegales!");
            check = false;
        }
    
}
return check;
}

function buttonsOn() {
    if(gameSession === true) {
        $("#c1").click(function() {
            $("#c1a").attr("src", "imgs/1.png");
        });
        
        $("#c2").click(function() {
            $("#c2a").attr("src", "imgs/2.png");
            });
        
                $("#c3").click(function() {
            $("#c3a").attr("src", "imgs/3.png");
                });
        
                $("#c4").click(function() {
            $("#c4a").attr("src", "imgs/4.png");
                });
        
    }
}

function gameStart() {
    var difficulty = $("#nivel option:selected").attr('id');
    switch(difficulty) {
        case "1":
    beginner();
    break;
case "2":
    intermediate();
    break;
case "3":
    advanced();
}
}

function beginner() {
    gameSession = true;
    buttonsOn();
}
edit: Any tips from the pros would be extremely welcome. I want to do this on my own but it's frustrating not even being able to get the first part right.

down with slavery
Dec 23, 2013
STOP QUOTING MY POSTS SO PEOPLE THAT AREN'T IDIOTS DON'T HAVE TO READ MY FUCKING TERRIBLE OPINIONS THANKS
Could you add the rest of your code into a jsfiddle? https://www.jsfiddle.net

pepito sanchez
Apr 3, 2004
I'm not mexican
jsfiddle is being a serious pain, needing me to completely break up my code in order to satisfy its need for me to only include what html, css, and js it wants in seperate windows.

down with slavery
Dec 23, 2013
STOP QUOTING MY POSTS SO PEOPLE THAT AREN'T IDIOTS DON'T HAVE TO READ MY FUCKING TERRIBLE OPINIONS THANKS

pepito sanchez posted:

jsfiddle is being a serious pain, needing me to completely break up my code in order to satisfy its need for me to only include what html, css, and js it wants in seperate windows.

For what it's worth, most pages are generally split up this way.

pepito sanchez
Apr 3, 2004
I'm not mexican
I do use Jsfiddle for small pieces of test code, but for a project this large, it's a serious pain in the rear end. What do you need to know? The html, I assume?

code:
<!DOCTYPE html>

<html>
    <head>
        <title>SIMON</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" type="text/css" href="css/estilos.css">
            <script type="text/javascript" src="jquery.js"></script>
            <script type="text/javascript" src="jsfile.js"></script>
    </head>
    <body>
        <div id="juego">
            <div id="simon">
                <div id="c1"><img id ="c1i" src="imgs/d1.png"></div>
                <div id="c2"><img id ="c2i" src="imgs/d2.png"></div>
                <div id="c3"><img id ="c3i" src="imgs/d3.png"></div>
                <div id="c4"><img id ="c4i" src="imgs/d4.png"></div>
            </div>
        
        </div>
        <div id="panel">
            
            <!-- INICIO LOGIN -->
            <div class="login clearfix">
                <h2>Login</h2>
                <hr>
                <label for="nombre1">Nombre jugador 1: </label>
                <input type="text" id="nombre1"/>
                <label for="nombre2">Nombre jugador 2: </label>
                <input type="text" id="nombre2"/>
                <label for="nivel">Nivel: </label>
                <select id="nivel">
                    <option id="basic" value="1">Básico</option>
                    <option id="inter" value="2">Intermedio</option>
                    <option id="advanced" value="3">Avanzado</option>
                    
                </select>
                <input type="button" id="comenzarJuego" value="Comenzar juego">
            </div>
                                            <div id ="emptyThreat"></div>
            <!-- FIN LOGIN -->
			 <!-- INICIO LOGIN -->
            <div class="login clearfix">
                <h2>Turno:</h2>
                <hr>
                <div id="turnoJugador">
					 Jugador 1
				</div>
            </div>
			
			
            
            <!-- TABLA CON DATOS -->
            <div class="tablas">
            	<table>
                <tr><th>Nombre</th><th>Puntaje</th><th>PG</th><th>PP</th><th>PE</th></tr>
                <tr><td id="name1">A</td><td>1</td><td>A</td><td>A</td><td>A</td></tr>
                <tr><td id="name2">B</td><td>2</td><td>B</td><td>B</td><td>B</td></tr>
                </table>
            </div>
            <!-- FIN TABLA CON DATOS -->
        </div>
    </body>
</html>

down with slavery
Dec 23, 2013
STOP QUOTING MY POSTS SO PEOPLE THAT AREN'T IDIOTS DON'T HAVE TO READ MY FUCKING TERRIBLE OPINIONS THANKS
Uhh I don't know what I need to know, I just think it'd be way easier to diagnose if we could see it in action (and get the dev tools packaged with most browsers)

pepito sanchez
Apr 3, 2004
I'm not mexican
I don't think jsfiddle would be much help anyway, since this project includes lots of source images. I only started using jsfiddle a couple of weeks ago, so I'm not sure how I would add images and stuff.

edit: Okay seeing your post now, I will have to add the complete thing to some kind of website, or something. But I have to go to my currently lovely job. I thought someone could figure out what I was obviously doing wrong with the function without the entire thing. Thanks anyway for your time.

down with slavery
Dec 23, 2013
STOP QUOTING MY POSTS SO PEOPLE THAT AREN'T IDIOTS DON'T HAVE TO READ MY FUCKING TERRIBLE OPINIONS THANKS
No problem, I mean, I can see what you're trying to do in subCheck but yes, there are much better ways and beyond that, trying to filter input like you're doing is one of those "solved" problems, something like a regular expression... or you could include a validation library(unnecessary imo) like http://jqueryvalidation.org/


for the regex route I would start here:
http://stackoverflow.com/questions/3532053/regular-expression-for-only-characters-a-z-a-z

pepito sanchez
Apr 3, 2004
I'm not mexican
Well I can't use anything outside of the standard jquery library and my own custom js. So that's a no-no. This will be a bigger issue once I have to implement audio for the divs later on in my code, since I can't use the better implemented libraries out there. But that's for a later time.

I've seen regex functions and simply don't fully understand them. That's an issue since I have to supply full documentation of my code. Anyways I should be able to understand my own code. Otherwise, what's the point?

Thanks again.

hedgecore
May 2, 2004

pepito sanchez posted:

My problem is getting the very first part down. This is mostly a skeleton for what's going to be a game.

I'm trying to get the player names in the form to validate, but for some reason it doesn't even check whether the name is too long or has the special characters I've specified. Yes, the game is in spanish, and my code is mostly not.

I'm just trying to get the names to validate correctly for now. How is my logic wrong?

It could be a dozen things, start using debugger; or console.log() or alert() to confirm you're even calling the submit() method on submit, or subcheck() on submit, and make sure that player1.name is set for instance (console.log() that). If something doesn't follow your conditionals as you'd expect, test each piece of them.

In reality it's probably because you're creating player1 and player2 as arrays, when really you want to create objects to store properties about each of them.

(replace lines 2 and 3 with this:)

code:
var player1 = {};
var player2 = {};

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Well the biggest problem I see is the ids "nombre1" and "nombre2" refer to <input> tags. so you can't do $("#nombre1").html("words"), the correct function is $("#nombre1").val("words")

The problem though is if you did that you would change the <input> tags' text, which contains the player's name. What you actually need to do is create a new <div> underneath the <input> tags and fill that with your "invalid username" html that you want to use and then clear the HTML when the user inputs a valid name.

pepito sanchez
Apr 3, 2004
I'm not mexican
poo poo that's probably all it is. Yeah I'm trying to create them as associative arrays. In the future I have to keep track of points and modyfy a table to order players depending on points. Good tip! I will test it out when I get back from work.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





I wrote a jsfiddle that shows my solution...

http://jsfiddle.net/Fbzgs/

hedgecore posted:

It could be a dozen things, start using debugger; or console.log() or alert() to confirm you're even calling the submit() method on submit, or subcheck() on submit, and make sure that player1.name is set for instance (console.log() that). If something doesn't follow your conditionals as you'd expect, test each piece of them.

In reality it's probably because you're creating player1 and player2 as arrays, when really you want to create objects to store properties about each of them.

(replace lines 2 and 3 with this:)

code:
var player1 = {};
var player2 = {};

This is bad, but not relevant to the problem since arrays are objects

pepito sanchez
Apr 3, 2004
I'm not mexican
Thanks for the fiddle. I actually did something similar before with my code, but the main problem was the way it formats with the existing CSS on the page. For some reason the error messages show up split and BETWEEN the two input boxes. As in, half a line and half a line. Weird... I tried putting the div in different positions, but it just ends up weirder. I think I'll need to mess with the CSS they've given us.

I just started learning associative arrays, and that's pretty much how our teacher's teaching us. I mean I could also make the whole object at the time. As in

code:
player1 = { "name": "",
                  "points": 0,
                  "gamesWon": 0,
                  "gamesLost": 0,
                  "gamesTied": 0;
};
But it seems kind of pointless establishing that global variable at the beginning, no? Isn't it better to keep things simple and just establish it as it builds up new parts?

pepito sanchez fucked around with this message at 02:54 on May 29, 2014

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

pepito sanchez posted:

But it seems kind of pointless establishing that global variable at the beginning, no? Isn't it better to keep things simple and just establish it as it builds up new parts?

Doing it in one go helps make the code self-documenting. You can see the structure of the object right away.

It gets especially bad when you have an object whose properties are defined inside different branches:

JavaScript code:

var someObject = {};

if (aCondition) {
	someObject.oneProperty = "Hello";
}
if (otherCondition) {
	someObject.anotherProperty = true;
} else {
	someObject.thirdProperty = 17;
}
You can't really know what properties or combination of properties that object has or could have.

Sometimes that happens, but I prefer initializing my objects all at once, if possible.

pepito sanchez
Apr 3, 2004
I'm not mexican
Well I did as you said, because it makes sense to do it for readability, at least. My main problem now is having a sequence of pictures show based on a random number array. In fact, I can't even get a picture to change for a certain amount of time before changing back once a player clicks on it, and only while playing a game.

I chopped off the code I made for on click events. Pictures weren't changing, so I know I was doing something wrong from the get-go. I think it's because I was making all of those click events inside of a function, and I simply called that function once, when the game initialized. I need to start fresh on that, specially since each click a player makes should add to its own seperate array, which later compares to the computer's random array to see if they match or not.

I made a fiddle. Graphics for the game are missing, but the code is all intact. I made an alert to make sure the code enters the beginner() function once the form is properly completed. It enters, but doesn't perform the sequenced event. No sounds play, and no images change on the screen.

edit:

http://jsfiddle.net/WcX8S/2/

edit2: Okay I fixed the beginner() array for loop, but when it plays, it only shows one color. Use if instead of else if? And the first div id never changes color. Am I off by one somewhere? I don't see it. Also, no sounds play, so I'm completely off on that regard.

pepito sanchez fucked around with this message at 20:17 on May 30, 2014

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

pepito sanchez posted:

Am I off by one somewhere? I don't see it.

randFour function returns a random number from 1 to 4, not 0 to 3.

pepito sanchez posted:

no sounds play, so I'm completely off on that regard.

You're trying to call play() on the jQuery object, not the DOM object: $("#snd3").play();. Try $("#snd3").get(0).play(); instead.

Wheany fucked around with this message at 13:25 on May 31, 2014

pepito sanchez
Apr 3, 2004
I'm not mexican
Got it. $("#snd3")[0].play();

And yeah I noticed I was off by one after staring at it long enough :/

a slime
Apr 11, 2005

Javascript newbie here, playing with Emscripten. The C code I'm compiling to Javascript is pretty small, a few dozen lines, but it's a lot of integer math that depends on overflows and etc and I'm too lazy to port it myself. Emscripten, with all of the options for size optimization, still dumps ~180K of boilerplate stuff in the output, most of which appears to be unused. My translated C code ends up being about !K of this.

Running the output through a minifier breaks it. Is there something I'm missing about Emscripten? Is there any way to tell it to size-optimize the stuff it's dumping into the output and not just my translated code?

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
What minifier are you using? If running it through Closure Compiler breaks it then that sounds like a bug in one of the two projects that you should report.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply