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
roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Is there an ES6-to-uglified-javascript compilation process that isn't a giant pain in the rear end to set up? I want to be able to do it from a command line, I don't want to install Java, and I want to have an easy path to debugging. The only thing I really want from ES6 is modules/namespaces/exports, which unfortunately seems to make running unmodified scripts in Chrome for debugging purposes not work.

I tried google-closure-compiler-js; the command line interface seems to ignore the flags it's described as using so it only ever removes whitespace and doesn't really uglify or do module wrangling, and npm installing a bunch of garbage to support its use another way ends up complaining about undeclared variables that are clearly declared and aren't mentioned at the places the errors are claimed to be at (with its webpack support), and then trying to run it complains $jscomp is not defined (which is supposed to be a polyfill), and the 'gulp' wrapper just doesn't work as described at all.

Before that I got about a hundredth of the way through the giant loving mess of hoops installing a Babel command line seems to require, and with the expectation that it's going to fail to mention a bunch of steps since right from the getgo it started out just assuming I had npm installed already.

Oh, I also tried typescript briefly, and foolishly made a copy of my original js file with a ts extension, ran the typescript compiler on it, didn't like what it was doing so I deleted the .ts file, not realizing the compiler had silently overwritten my original modern js file with an ugly backward-compatible version, so I had to spend half an hour undoing that poo poo.

I disliked typescript because apparently by design it hates this:
code:
function foo(a, b, c, d, e, f) {}
function bar() {return [1, 2];}
foo(...bar(), ...bar(), ...bar());
(It complains that foo requires 6 parameters and is passed at least 0. And calls this an error.)

Should I just give up on the idea of moduling my code? I've done modules, but only in a context where all the build tools are already set up, I'm just not convinced it's worth the effort of figuring out all the build tools for my little home projects.

roomforthetuna fucked around with this message at 07:10 on May 19, 2018

Adbot
ADBOT LOVES YOU

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Tanners posted:

Typescript here wants you to indicate that those parameters are optional. You can add a ? To the end of the parameter names and that should compile fine.
I suppose that works okay if you don't mind writing wrappers around things, eg, if foo in my example had been canvasContext.bezierCurveTo. The deeper problem really is that there's no way to define a type as "an array of exactly 2 elements" or, even better, "an array that has an even number of elements that is at least 2".

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Roadie posted:

You need to explicitly define a tuple type for bar, as otherwise it will infer an array of indeterminate length.
Ah, fair enough, I just didn't give typescript enough of a chance, then. And its eating my original source without warning I guess can be considered my fault, I shouldn't have assumed "tsc xxx.ts" wouldn't silently overwrite xxx.js with its output.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Hm, I just noticed scrolling back up that I never actually posted my reply where I said thanks for the parcel suggestion, it is hugely less frustrating than trying to set anything else up, and the results aren't bad at all.

I think I started elaborating on "thanks" then went looking for an example of something, and got distracted. So, thanks!

Aha, I found the tab with the unposted post in it.

quote:

Thanks! Working in minutes, and helpful errors ("x is readOnly" where I tried to set an imported value, rather than "x is not defined" that I was getting with google-closure-js).

A little bit shaky on the debug build - it's mostly good, but it seems to have a problem with colliding map files such that it debugs into the wrong code (and I only have 4 files right now!)

But the "no configuration" promise was pretty much true, and it does exactly what I wanted.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

prisoner of waffles posted:

Thoughts? (prayers?)
I think "oh thank goodness, it's not just me who finds all this stuff to be a loving mess."
And I hope you can transition to something less grotesque.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

LifeLynx posted:

I want to do something incredibly simple and commonplace, but I can't find an answer for it. I want to animate (fade-in and up) when an element would scroll into view. I can't find a vanilla JS or even jQuery answer for this, but maybe I'm trying to reinvent the wheel here? Is there a script anyone can recommend to do this fancy animate when scroll into view stuff with minimal bloat?
You can do this sort of thing with nothing but CSS these days, it's pretty impressive.
https://www.w3schools.com/css/css3_animations.asp

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Is there a WebRTC guide suitable for games somewhere (ie. I don't need to know about streaming video or media bits, I just want peer-to-peer data channels as simply as possible without having to use any particular framework; a small standalone library is fine).

I recognize that I have to do something server side, which seems to be just "transmit a single JSON object from the WebRTC host to the WebRTC client" if I understand things correctly(?). And it also seems to be recommended to run a STUN and/or TURN server to avoid an external dependency on those things, maybe?

And I recognize that it's going to be horrible, because network communication is always horrible. It's just this initial connection-forming bit that is unfamiliar and all the "simple instructions" I find go immediately to "here's how to stream a video" and then "now you're done, yay!" which is not really very similar to what I want.

I'm sure I could figure it out from the API documentation but it seems likely there's something better out there and I'm just missing it in my searches, like I was missing parceljs.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Chenghiz posted:

Put a link to site A on site B and check its style using getComputedStyle to see if it's been visited or not.
If you're going to do it by requesting between sites you could use cross-origin resource sharing and make a proper AJAX request of the other site, rather than trying to infer information from styles.
Or go nuts and encode your information into the colors of a png-encoded image, since those are allowed cross-site by default.

Edit: later realized the suggestion I'm replying to was not to load something from the other site but to literally just put a link and interpret whether the browser styles it :visited or not.

roomforthetuna fucked around with this message at 00:56 on Jun 20, 2018

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

IAmKale posted:

roomforthetuna is talking about CORS. It's something configured server-side as a security measure to limit which websites can make requests to that server. For example it can be used to restrict code in a .js file loaded in http://bar.com from making requests to API endpoints at http://foo.com.
This description seems weird to me - the thing is more that javascript is generally restricted by the browser from making cross-site requests for data (except then people worked around this by returning a page of generated javascript that calls a function with the data, and at the client-side modifying the DOM to add new 'script' elements to make the request, so I'm not really sure what purpose the restriction serves other than to make it more of a pain in the rear end. If anything this restriction causes security issues by making people run foreign javascript to call an API instead of being able to just communicate in data).

Anyway, my point here is that the server-side CORS configuration (which is headers you send with the page) is not so much used to restrict a script from making requests of foreign endpoints, but rather is used to tell the browser to not restrict those requests like it normally would.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
I just learned async/await. It makes regular Promises look stupid (except for those edge things where you have to put a Promise around some old callback-type function to make it async-able.) But for like 95% of asynchronous things it's great. And especially for unit tests, where promises are loving terrible.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Lumpy posted:

Async uses Promises under the hood. Makes you think.
I knew that, and it did make me think, mostly I wonder how that works with something like this:
code:
for (let i = 0; i < 5; i++) {
  await someFunc[i]();
  console.log(i);
}
Mapping that to Promises seems tricky. I mean I could write something with Promises that does that, but mapping it automatically, specifically, seems tricky.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

FSMC posted:

*What does the "=>" mean
(aaa, bbb) => {some stuff}
is mostly equivalent to
function (aaa, bbb) {some stuff}

Except the arrow version doesn't have its own "this" and "arguments" bindings, it inherits those from its scope, where the "function" version has its own. 90% of the time it doesn't matter, and 90% of the *rest* of the time, the arrow version is more likely to be what you expected than the "function" version.

(There are some other differences you almost certainly don't care about at this level.)

Edit: also the thing to search for if you want to learn more about it is "arrow functions".

roomforthetuna fucked around with this message at 04:19 on Jul 15, 2018

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

geeves posted:

Careful with forEach on a NodeList it's not exactly the same as an array. Babel probably takes care of this, but just in case, you probably are safer with:
I don't know why you'd even use forEach these days, now that there's the "for (x of y)" syntax, other than ingrained habit from The Time Before.
forEach is horrible to debug and horrible to reason about.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Suspicious Dish posted:

The performance of for...of is terrible, since it requires an allocation on each loop, and next() has not been optimized in most engines. forEach and for loops don't have that issue. I've gotten multi-FPS speedups by changing for...of to forEach in some of my work.
That seems weird, can you elaborate? Why does for...of require an allocation each time? It seems like
for (let a of list) { ... }
should be equivalent to
for (let i = 0; i < list.length; i++) {let a = list[i]; ... }
except for not taking up any namespace for i.

(Edit: if the 'a' is the allocation then I would think forEach would require the same allocation for the 'a' in list.forEach((a) => { ... }).)
(Edit2: are you think of it as it applies to key-values rather than arrays, where you have to do Object.keys(map) and *that's* the allocation? I do see the value in forEach for key-value situations.)

roomforthetuna fucked around with this message at 22:30 on Jul 18, 2018

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Aha, thanks for the explanation. And that makes me sad.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
I'm trying to get my head around the behavior of node_modules (with typescript).

It seems like the standard way of installing your module dependencies is "npm install whatever" in your project path, which makes a node_modules folder, which seems like ... a heap of crap. I don't want all the dependencies of a project in the same path as that project. But it seems that "npm install -g whatever" to install things in the global space doesn't make them available for imports?

What's the non-stupid way of doing this? I must be missing something. People do this with git, and surely don't have all their dependencies in their git repositories - do they just put node_modules in their .gitignore? If so, are the dependencies captured somewhere else so there's a record of what your module needs somewhere? Or are you supposed to set it up so you do npm install somewhere *above* your project path?

Everything I find saying how to do things just seems to manually mash the node_modules dependencies right into the middle of your project, surely that can't really be the way?

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Aha, thanks guys. So I was close to guessing right, it just seems weird, having the same module installed in multiple places if you work on multiple things. Oh well.
And thanks for the --save tip, that seems less irritating than having to do the install and modify the file manually. (Though as you say, does seem weird that it's not the default.)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Joda posted:

I put them in global and link to projects. Is that bad?
How do you do that? I would rather do it that way, I just couldn't get it to work.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

evilfunkyogi posted:

Or work on multiple projects that might need different versions of the same package.
I mentioned this system at work and someone asks the interesting question, what happens if you work on two projects where one depends on the other and they both depend on the same external dependency, but have different versions in their package file? Does npm just say "gently caress you, make these versions the same"? Do you end up with both versions in your target?

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Also, if you hate bundled JS for potentially being a horrifying giant file most of which isn't used, there is dynamic importing, but it's significantly more of a pain.
(Dynamic importing, code splitting)

(I'm using this because I'm trying to make multiple minigames through one interface operating with persistent WebRTC connections - loading the minigames only on demand makes sense.)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Speaking of which, now I have a problem. (Or "you have a problem, so you decided to use webpack, now you have two problems.")

I'm trying to do a webpack config that can build two things. At the moment I've disabled one of them while I work on the other, but webpack keeps trying to build files it should have no reference to.
ie. with the following webpack.config.js I get
ERROR in [...]\client\somefile.ts
When as far as I can tell it shouldn't be looking in /client/ at all, no files in there are referenced by any of the files in /server/. What am I misunderstanding? It it just trying to build all ts files below the current path just in case I might want them at some point?

code:
const path = require("path");

const serverConfig = {
    target: 'node',
    entry: './server/main.ts',
    mode: 'production',

    output: {
        path: path.join(__dirname, 'dist'),
        filename: '[name].bundle.js',
        chunkFilename: '[name].chunk.js'
    },

    resolve: {
        extensions: ['.js', '.ts']
    },

    externals: ['ws'],
    module: {
        noParse: [/^ws$/],
        rules: [
            {
                test: /\.ts$/,
                include: [path.join(__dirname, 'server')],
                loader: 'ts-loader',
                options: { configFile: 'tsconfig.server.json' }
            }
        ]
    },
};

//module.exports = [serverConfig, clientConfig];
module.exports = [serverConfig];
Edit: just to be absolutely sure the files aren't referenced by anything I expect to be building I renamed somefile.ts to somefile2.ts, which provoked the same error but with somefile2.ts, so it's definitely not some stray reference.

roomforthetuna fucked around with this message at 21:05 on Aug 26, 2018

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
I found the answer to my own question - a missing option with a surprising default:
code:
module: {
  rules: [
    {
      loader: 'ts-loader',
      options {
        onlyCompileBundledFiles: true,
      }
    }
  ]
}

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

roomforthetuna posted:

I found the answer to my own question - a missing option with a surprising default:
Also, similarly, webpack-node-externals is a thing you apparently want to do to stop typescript node targets from whining about all the dependencies not being quite typescripty enough in various ways.
These defaults loving suck, this build system loving sucks, and so do all the others, argh, I should have just used makefiles.

Edit: also tsconfig-paths-webpack-plugin sigh.
Edit2: vvvv Yeah, fair enough, getting the ONE external dependency I want to use to work with makefiles would probably have been as much hassle as all this stupid poo poo.

roomforthetuna fucked around with this message at 04:24 on Aug 29, 2018

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Joda posted:

Busy waiting (which is what that is,) and sleeping aren't the same thing, and pure busy waiting is bad concurrency practice regardless of language.
Or even if you're not doing concurrency. Busy waiting makes people's processors get hot.
Edit: if you're going to busy-wait, at least mine a bitcoin or something with those 'idle' cycles.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Generally, you want to use arrow functions when you're using them as functions to pass around, and function() functions when you're defining members or scoped standalone real functions. In the majority of cases doing this will give you the intuitive behavior rather than the confusing behavior.
Doom Mathematic gave the example where arrow functions in the wrong place gives you confusing behavior.
The example where function() functions in the wrong place gives you confusing behavior is something like:
code:
class HerpDerp {
  constructor() {
    this.glorp = "hello!";
    this.button = document.createElement('button');
    this.button.addEventListener('click', function(event) {
      alert(this.glorp);
    });
  }
}
new HerpDerp();
If I'd used an arrow function there, when you click the button a "hello!" alert will be triggered. As written, I don't know, probably an alert that says null or maybe no alert, because 'this' inside the event listener function in that case will be ... maybe the button? Not the HerpDerp anyway. Maybe there is no this and it throws an exception.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Is there a typescript+webpack solution for debug logging that gets completely elided from final distributed code?

I want to log to the console while I'm developing, because I have a fairly complicated websocket thing going on that I'd like to easily see what communication is happening, but in a release version I'd like that logging code not just uncalled but removed.

I found libraries but they don't seem to do elision. I found you can get uglify to elide useless code, define DEBUG, and then do DEBUG && console.log(...) every time, but that seems verbose.

I found grunt-strip, that does what I want with grunt and js, but I don't know how I'd apply that in webpack+ts.

I found webpack-strip-debug, which again seems to be applying to js not ts, maybe it could be chained after the ts compile step?

Not even edit, answered my own question, but sharing because someone else might be interested:
code:
yarn add --dev strip-loader
And in webpack.config.js (where clientConfig is one of my exported config objects, and -d is used for my debug build):
code:
if (!process.argv.includes('-d')) {
    console.log('Removing debug');
    clientConfig.module.rules.unshift({
        test: /\.ts$/,
        loader: WebpackStripLoader.loader('debug'),
    });
}
And then I added a module debug
code:
export function debug(...a: any[]) {console.log(...a);}
Then I can just do debug("here is a message", some_value) in code, and it gets stripped from the non-debug build. I think I still leak the now-unused function debug; could probably get that elided by adding a closure compiler or uglify pass at the end.
(I could more easily just strip all console.log, by doing WebpackStripLoader.loader('console.log') instead of 'debug' but sometimes I want to leave a console.log in.)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Hypnobeard posted:

I'm just starting out in Javascript/ES6, so this is confusing the heck out of me. What am I missing, either in my file or in the test spec?
You've exported isLeap as default, but you've imported it by name.

You either want
code:
export const isLeap = year ...
Or
code:
import isLeap from './leap';
(maybe "import isLeap as * from", I'm not sure, I don't use default exports myself.)
Or a different syntax of export.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Hypnobeard posted:

Removing the braces fixed it. (ESLint was complaining if I tried to shift to export const.. without a default.)
It might be exports = { isLeap }; if you want multiple exports.
So many ways of doing modules, each just different enough to be confusing. I'm using typescript now so everything is slightly different another different way.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Suspicious Dish posted:

import * as Foo from './foo'; is what I use but they chose the ugliest import syntax for a really good idea
I don't mind that too much, because it means you can do
code:
import * as Foo from './foo';
Foo.doAThing();
Foo.doAnotherThing();
Foo.doAThirdThing();
in one client file, and then
code:
import {doAThing} from './foo';
doAThing();
in another where you're confident there's no namespace collision and you don't want to import too many things.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
I've changed my mind, I do dislike
import * as Foo from '...'
because I want the syntax for that to be just
import Foo from '...'

Having a default and individual exports is weird, I expect individual exports to just be combined into the single default exported object, and
import {a, b, c} from '...'
to be essentially interpreted as destructuring that single exported object.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Hypnobeard posted:

Thinking about it, my question is more "how do I get the error in an Array?"--because the ways I know about don't seem to produce what the test is looking for.
I don't think the square brackets in the test output signify that it wanted the error to be thrown in the form of an array. It looks more like it was just trying to be clear about where the ends of the string are.
(Especially since you showed the test code and it wasn't saying expect it to throw an array.)
It is a bit poo poo of the framework not to use the same delimeters for the "what you got" output though.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
If you use yarn link / npm link, and then modify the dependency package, what behavior should you expect?
1. Like makefiles the change magically resolves and your final dist just works with the new files.
2. You have to do some sort of build operation to a dist folder on the dependency package, but then the new files will work.
3. You have to do some sort of build operation to a dist folder and then also do the whole link process again.

(Asking rather than trying because right now I just have modules from relative paths, and converting those paths to packages is a moderate amount of work that's not worth doing if it's just going to make my workflow worse. I'm only considering it because for some reason the remote-linked modules are complaining about missing tslib if I try to write async/await things, even though their closest tsconfig.json is essentially identical to the one near the non-remote-linked modules which can do async/await things just fine.)

Edit: my current workaround is just writing async functions in the form of functions that return promises and do all that awkward loving around with .then(), which I can keep doing if it's not worth the effort of packaging things properly while they're in parallel development.

roomforthetuna fucked around with this message at 06:08 on Sep 21, 2018

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Joda posted:

E2: Found the issue. I was calling the function from another component, and the function inherited the scope I guess.
I guess this was something like
code:
setTimeout(someObj.someFunc, 1000);
Which tends to mess with the "this", because you're passing the function pointer, which doesn't come with embedded 'this'.
You can instead do this kind of thing like
code:
setTimeout(() => someObj.someFunc(), 1000);
This way setTimeout's function pointer is to the lambda that calls someObj.someFunc - when you call a member function via its owner that implicitly includes giving it the 'this' parameter, but if you use it as a variable it's just a function pointer and doesn't have any bound parameters.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Bruegels Fuckbooks posted:

[prefer bind] it's a little terser
.bind(this) adds 10 characters, the lambda adds 8 characters including spaces, as few as 6 if you skip the spaces.

The "more explicit" thing is an okay reason though. I prefer the lambda because I use it elsewhere too - not using bind means one fewer thing I have to remember how it works.

Edit: oh wait, someObj.someFunc.bind(this) would do the thing that you probably *don't* want, anyway. someObj.someFunc.bind(someObj) would be the thing you more likely want to do.

roomforthetuna fucked around with this message at 02:10 on Nov 11, 2018

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Munkeymon posted:

It's still prototype-based and you still have to bind methods that care about having the class's this available.
For languages that are class-based you still have to bind a 'this' to a function you're referencing like a function pointer. In C++, for example, you have to call a member function pointer with an explicit this.
Any language that *doesn't* require you to do it is still just doing it for you in secret. The difference with Javascript is that it won't tell you you're doing it wrong, it'll just do the wrong thing.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Munkeymon posted:

Is it that common to call members functions/class methods as function pointers from other methods in the same class in C++?
Not any more, because now you'd generally just lambda it up, like you do if you're doing it right in JS. :)
But before lambdas, yeah, maybe not common, but not uncommon.
Edit: common enough that "member function pointer" is a thing at all. It's not like they have much other purpose.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

huhu posted:

1. Is it worth it to learn "Vanilla JavaScript"? I feel like at this point I know a solid amount of stuff about JS. In the Electron tutorial I understand selectors and such but I'd much rather work with JSX and JS than deal with the actual intersection of HTML and JS.
I've not done React, but I went from jQuery to vanilla and find it less irritating because it doesn't have secret sauce behind everything you try to do, it just does what you ask it to. Though there are occasional irritations like checking whether something is 'visible' (ie. not hidden, not display:none, not size 0) is weirdly awkward with vanilla JS and there's a function for it in jQuery.
I know other people who mostly use React and find it a relief when they're allowed to just use vanilla JS.
A strong benefit of not using some framework is that vanilla JS seems much less likely to get changed out from under you and force you to rewrite a bunch of stuff. But maybe I've just been super unlucky with being burned that way literally every time I use any kind of framework for anything.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

necrotic posted:

No, I mean literally the value at array.length. Not some code analysis.
I think the point being made is it probably *is* a very small speed improvement, because putting the length in a local variable is one lookup per iteration, whereas getting it out of array.length is two (one for the location of the array and another for the location of the array's length property). Perhaps even worse if array.length goes through a getter function. Sure, using array.length each iteration isn't making the loop O(n^2) or anything, but in a non-compiled language using a plain variable is almost certainly [very slightly] faster than using a member property.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Munkeymon posted:

After doing i++ for years just because that's how all the examples I learned from do it, I thought about it for a minute and realized that ++i is the operation I actually wanted/needed, so started doing it that way instead. Like if you have two equivalent functions that mutate a thing but one returns a value that you just don't use, I stop and wonder why.
I assume the prevalence of i++ is because ++i doesn't follow the pattern of almost every other mutation operation, leading with the thing that is to be mutated.
i = 5;
i += 5;
i.update();
i = someSortOfOperation(i);

The only other thing that comes to mind where the mutated thing is at the tail is functions with output parameters, which tended to be a workaround for functions only returning one thing, which is increasingly not true these days (C++ returning tuples, Javascript returning objects or arrays and deconstructing at the call site, etc.)

Adbot
ADBOT LOVES YOU

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Lumpy posted:

"I have 3 days to write this, and I don't think learning typescript and getting the tooling all set up will fit in that."
This is good estimating.

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