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
Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Remember I wrote a simple configuration tool once open source on npm. It was written in javascript, because it's tooling. Not everyone writes Typescript backends, and once you've added it to your config you're done with it forever.

Got hounded about adding typescript support for months, to the point where I said fine if you write a good typescript implementation I'll merge it. Then all of a sudden it was "oh i meant you should do it". After that I just said on the readme "don't ask about typescript" and I left the numerous issues up so that anyone could see this discussion had already happened.

Typescript absolutists are annoying is what I'm getting at.

Adbot
ADBOT LOVES YOU

gbut
Mar 28, 2008

😤I put the UN🇺🇳 in 🎊FUN🎉


There one thing that's worse than JS and that's TS that is riddled with `any`s.

I've been using TS almost exclusively for the last few years, after a decade+ with JS, and I will not start a new project of any serious complexity in JS these days. A nice type system is just so much easier to reason with, even if it's not perfect at this stage. I'd rather have the compiler warn me about me misremembering a function signature than see the issue pop up later during runtime just because JS was kinda able to run with it.

Nolgthorn posted:

Typescript absolutists are annoying is what I'm getting at.

But this also. Just use the right tool for the job.

MrMoo
Sep 14, 2000

I've been looking for reference libraries for handling scheduling, i.e. iCal format in an ECMAScript flavouring, apparently there is a recent update to the JSON version (RFC8984 ). There is a Google Apps Script API which looks nice enough front end too. So there are three main implementations, rrule.js, rSchedule, and dayspan. All three use TypeScript and dive into code golfing a bit too much. It's when the business logic of an implementation is 10 lines of code, but they push 1 million lines to a repo. It wouldn't be bad if the implementations worked, were maintained, had usable documentation.

rrule.js randomly broke their repository, and somewhat impressively causes Chrome to fault so much it cannot show an error. rSchedule went to the template mall to satisfy problems no one has, like it "supports" 6 different DateTime implementations? They all have a long list of open bugs and missing functionality of the iCal spec. There is a lot of effort doing something with these projects.

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!

Nolgthorn posted:

Remember I wrote a simple configuration tool once open source on npm. It was written in javascript, because it's tooling. Not everyone writes Typescript backends, and once you've added it to your config you're done with it forever.
Yeah, npm is pretty annoying to typescript-integrate too. I wrote my serializing-to-and-from-binary library in typescript and its schema generator in node-javascript, and getting the typescript library part to play well and import from npm correctly was way more painful than anything else in the process.

(Not that npm is exactly a joy to work with at the simplest of times.)

FuzzySlippers
Feb 6, 2009

So just making sure this is still correct as of now (since these things drift over time): there is no ironclad way to get a class name at runtime? I've noticed even without minifying constructor.name sometimes comes up weird and it seems like the conventional wisdom is not rely on it.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I assumed variable names and class names are inherently anything and change because any number of different tools. If I needed a dictionary I'd build one explicitly.

JavaScript code:
const CLASSES = {
    MyClass,
    AnotherClass
};
etc

Then something like;

JavaScript code:
function getClassName(subject) {
    for (const [key, value] of Object.entries(CLASSES)) {
        if (subject instanceof value) return key;
    }

    return undefined;
}
Or, maybe

JavaScript code:
const CLASS_NAMES = new Map();
CLASS_NAMES.set(MyClass, 'MyClass');
CLASS_NAMES.set(AnotherClass, 'AnotherClass');

const className = CLASS_NAMES.get(MyClass);
Or, maybe

JavaScript code:
class MyClass {
    className = 'MyClass';
}

const className = new MyClass().className;

Nolgthorn fucked around with this message at 13:09 on Oct 21, 2022

necrotic
Aug 2, 2005
I owe my brother big time for this!
https://jsfiddle.net/xmdsja3w/2/

The class itself has a name, the constructor is just a Function that gets created anonymously for the "class". If you minify the name will change, though!

FuzzySlippers
Feb 6, 2009

I get a typescript error saying name doesn't exist for an abstract class like this
code:
    public static Store<T extends Command>(cmd : T){ // Command is an abstract class
        console.log(cmd.name); // Property 'name' does not exist on type 'T'
The solution I'm doing now is a string type field that classes need to provide but I hate that kind of thing (if you duplicate an existing class to create one it's easy to forget to change it).

I'm just playing around porting over my custom ecs from c# that uses a lot of generics for things like checking if an entity has a component X, gimme a list of all component X, gimme any entity that has X components, etc. The solutions in ts seem like awkward boilerplate at least for the various ts/js ecs setups I've seen on git.

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!

FuzzySlippers posted:

I get a typescript error saying name doesn't exist for an abstract class like this
I think you actually wanted T.name, because you're trying to get the name of the class not a name member from the object?

But also that won't work because of the way Typescript does templates. When you do a template in C there is generated code for each specialization of T, so the function knows what T is while you're in it, but when you do a template in Typescript it's effectively just a loose constraint on what compiles to a single Javascript function, so there is no knowledge of what T is here for the javascript to retrieve a name from.

Edit: so yeah doing this in js/ts is gonna be awkward boilerplate.

roomforthetuna fucked around with this message at 02:08 on Oct 22, 2022

FuzzySlippers
Feb 6, 2009

roomforthetuna posted:

I think you actually wanted T.name, because you're trying to get the name of the class not a name member from the object?

But also that won't work because of the way Typescript does templates. When you do a template in C there is generated code for each specialization of T, so the function knows what T is while you're in it, but when you do a template in Typescript it's effectively just a loose constraint on what compiles to a single Javascript function, so there is no knowledge of what T is here for the javascript to retrieve a name from.

Edit: so yeah doing this in js/ts is gonna be awkward boilerplate.

I can't seem to do anything like that with just T. Just T seems to only work for casting. To get behavior like typeof(T) in c# I did find this a while ago

code:
export type ComponentParam<T extends IComponent = IComponent> = new (
    ...args: any[] ) => T;

//used for 
    public Get<T extends IComponent>(c: ComponentParam<T>): T | undefined {
        for (const component of this._components) {
            if (component instanceof c) {
              return component as T;
            }
        }
        Engine.LogWarning(`${c.name} not found on ${this.name}`);
        return undefined;
    }

//works like
var pos = entity.Get(PositionComponent); 
console.log(pos?.value);
which I'm not entirely sure how it works as I pulled it off a random gist. The type declares an interface for a constructor and the class itself satisfies that and makes it survive the transition to runtime or some such? It seems to work pretty reliably, but I'm not sure if it actually is reliable and it is a bit more verbose.

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!

FuzzySlippers posted:

which I'm not entirely sure how it works as I pulled it off a random gist. The type declares an interface for a constructor and the class itself satisfies that and makes it survive the transition to runtime or some such? It seems to work pretty reliably, but I'm not sure if it actually is reliable and it is a bit more verbose.
You can use T for casting because casting doesn't actually do anything.

Think about what the javascript is that the typescript compiles into, essentially, to understand why some things work and some don't. All the type information is stripped away entirely, so casting becomes nothing, which is fine, but it can't compile to UnknownClassType.name or new UnknownClassType() which is why you can't do those things with a templated T-value. You can't even do if (obj instanceof T) because instanceof compiles to javascript, and T does not exist in javascript.

MrMoo
Sep 14, 2000

My brain has stopped working, JS by reference, how does one access the updated value of a within the returned object?
JavaScript code:
> f = function() { let a = 1; return { a, b: () => { return ++a; } }; }
&#8918; ƒ () { let a = 1; return { a, b: () => { return ++a; } }; }
> g = f()
&#8918; &#9654; {a: 1, b: f}
> g.b()
&#8918; 2
> g
&#8918; &#9654; {a: 1, b: f}
> g.b()
&#8918; 3
> g
&#8918; &#9654; {a: 1, b: f}
🤯

MrMoo fucked around with this message at 17:51 on Oct 24, 2022

gbut
Mar 28, 2008

😤I put the UN🇺🇳 in 🎊FUN🎉


MrMoo posted:

My brain has stopped working, JS by reference, how does one access the updated value of a within the returned object?

The function 'b' returns the value of the closure variable 'a' after updating.
The value 'a' in returned object will always return the value of 'a' at the moment the function 'f' was executed (it gets baked in at 'f()')
To access updated a, you basically need to return a getter in your object, similar to 'b' just without the increment, which would be '{..., c: () => { return a; }}'
At least it looks like that to me.

e: this is a common technique to make variables 'private' in JS (by using closures) as JS doesn't have that facility built-in.
e2: small tip, you don't need 'return' on arrow functions if you want to return the expression directly, in a one-liner, so 'b: () => ++a' and 'c: () => a' do the same thing as the above code

gbut fucked around with this message at 18:07 on Oct 24, 2022

MrMoo
Sep 14, 2000

A direct getter would be:
JavaScript code:
f = function() { let a = 1; return { get a() { return a; }, b: () => ++a }; }
We have private fields in whatever version of ECMAScript is current.

It's weird to read as the syntax looks similar to normal closure, arrow function usage, but the result is different.

gbut
Mar 28, 2008

😤I put the UN🇺🇳 in 🎊FUN🎉


MrMoo posted:

We have private fields in whatever version of ECMAScript is current.

Thanks for the correction. I knew private fields were in the works a while ago, but didn't check when they got adopted.

ThePopeOfFun
Feb 15, 2010

Very new here. Working through a basic to do list to get my head around Javascript. The tutorial throws everything into an .html file. This works. If I separate files into .html, .css and .js, only one snippet does not work. I'm working in Visual Studio code. Chrome is up to date.

code:
var list = document.querySelector('ul');
list.addEventListener('click', function(ev) {
alert("test")
  if (ev.target.tagName === 'LI') {
    ev.target.classList.toggle('checked');
  }
}, false);
I never get to the test alert. Any thoughts?

necrotic
Aug 2, 2005
I owe my brother big time for this!

ThePopeOfFun posted:

Very new here. Working through a basic to do list to get my head around Javascript. The tutorial throws everything into an .html file. This works. If I separate files into .html, .css and .js, only one snippet does not work. I'm working in Visual Studio code. Chrome is up to date.

code:
var list = document.querySelector('ul');
list.addEventListener('click', function(ev) {
alert("test")
  if (ev.target.tagName === 'LI') {
    ev.target.classList.toggle('checked');
  }
}, false);
I never get to the test alert. Any thoughts?

Where in the HTML file is the script tag? If it’s before the <ul> tag the script won’t see it.

If you open your browser developer console there may be an error logged.

ThePopeOfFun
Feb 15, 2010

Bet that’s it. Script is at the top.

Edit: Moving script to the bottom fixed it. Thanks.

ThePopeOfFun fucked around with this message at 23:40 on Oct 24, 2022

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Best solution is to put all your code inside of

JavaScript code:
document.addEventListener('DOMContentLoaded', () => {
    // code here
});

MrMoo
Sep 14, 2000

Reminds me the awful Chrome team channel on YouTube, so much grandstanding and smugness all around.

https://youtu.be/_iq1fPjeqMQ

I think they're all on the Chrome 107 render blocking API now, as if that has any developer friendly usage (oh no, it's called DX "Developer eXperience").

https://developer.chrome.com/blog/new-in-chrome-107/#render-blocking-status

MrMoo fucked around with this message at 17:05 on Oct 26, 2022

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 way in Typescript to conveniently do something like named parameters, with defaults, where you also just keep the parameters in a single variable?

code:
interface FartParams {
  stink: number;
  visibility?: number;
  volume?: number;
}

class Butt {
  // Like this has the defaults but you have to duplicate everything to put it in a FartParams variable.
  constructor(public buttockCount: number, {stink, visibility = 0.1, volume=100}: FartParams) {
    this.fartParams = {stink, visibility, volume};
  }

  // Or like this has the params conveniently, but no defaults.
  constructor(public buttockCount: number, public fartParams: FartParams) {}
}
Or you can make a helper function that takes FartParams and returns FilledFartParams, but that's not convenient at all. Is there a good option?

(In the real example there's a lot more than 3 values so each additional case of duplicating everything is significant pain, and positional variables, that do the effect more easily, make the code unreadable.)

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
You could access the original object through the arguments array. But this doesn't help you - the way you're doing things, the default values only appear when you do the destructuring.

Can I ask why you want to keep these as a single "params" object instead of using the parameters individually?

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!

Jabor posted:

You could access the original object through the arguments array. But this doesn't help you - the way you're doing things, the default values only appear when you do the destructuring.

Can I ask why you want to keep these as a single "params" object instead of using the parameters individually?
Making them individual is one additional repetition right off the bat ("params: FartParams" versus "{a,b,c,d,e,f,g,h,i,j,k,l}: FartParams"), then if you want to store them in the class that took them in the constructor there's another repetition (you can't do {public a, public b} etc. so now you have to declare them all as members), and *another* repetition because you have to do this.a=a, this.b=b, etc in the constructor, which also means you're doing n operations in the constructor rather than just copying the reference. And then if you want to use these parameters (or a subset of them) in other functions or other classes you have to repeat them all again there too.

necrotic
Aug 2, 2005
I owe my brother big time for this!

roomforthetuna posted:

Making them individual is one additional repetition right off the bat ("params: FartParams" versus "{a,b,c,d,e,f,g,h,i,j,k,l}: FartParams"), then if you want to store them in the class that took them in the constructor there's another repetition (you can't do {public a, public b} etc. so now you have to declare them all as members), and *another* repetition because you have to do this.a=a, this.b=b, etc in the constructor, which also means you're doing n operations in the constructor rather than just copying the reference. And then if you want to use these parameters (or a subset of them) in other functions or other classes you have to repeat them all again there too.

If your destructuring the params object you’re _already_ doing n operations.

One option to do what you want is to define a dict of defaults and merge them like this:


code:
this.params = {
   …defaults,
   …params,
}
The defaults will get replaced by any keys set in params.

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:

If your destructuring the params object you’re _already_ doing n operations.
True, but you're doing n operations *twice* then, when you destructure it *and* put it into member variables.

Mind, I'm not super concerned about the performance, it just sucks to be have code that's inefficient to write, inefficient to execute *and* not particularly readable either. Feels like if I have to make a lot of effort, it should be at least compile to code that runs better. But it seems the only option for performance is positional parameters, which makes all the non-performance considerations significantly worse.

quote:

One option to do what you want is to define a dict of defaults and merge them like this:
code:
this.params = {
   …defaults,
   …params,
}
Ah, yeah, thanks, that's probably what I was looking for. Probably worse initialization performance than wrapping it in an object with getters, but very much more readable and debuggable and less painful to write. And more performant on read.

necrotic
Aug 2, 2005
I owe my brother big time for this!

roomforthetuna posted:

True, but you're doing n operations *twice* then, when you destructure it *and* put it into member variables.

Mind, I'm not super concerned about the performance, it just sucks to be have code that's inefficient to write, inefficient to execute *and* not particularly readable either. Feels like if I have to make a lot of effort, it should be at least compile to code that runs better. But it seems the only option for performance is positional parameters, which makes all the non-performance considerations significantly worse.

Ah, yeah, thanks, that's probably what I was looking for. Probably worse initialization performance than wrapping it in an object with getters, but very much more readable and debuggable and less painful to write. And more performant on read.

I wouldn’t be concerned with the performance aspect of either approach at all. What that compiles to is going to be more efficient than you could do by manually unrolling (with destructuring and restructuring) and even that wouldn’t be something to be concerned with in almost all cases.

Ergonomics is what matters more here.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

roomforthetuna posted:

True, but you're doing n operations *twice* then, when you destructure it *and* put it into member variables.

Mind, I'm not super concerned about the performance, it just sucks to be have code that's inefficient to write, inefficient to execute *and* not particularly readable either. Feels like if I have to make a lot of effort, it should be at least compile to code that runs better. But it seems the only option for performance is positional parameters, which makes all the non-performance considerations significantly worse.

Ah, yeah, thanks, that's probably what I was looking for. Probably worse initialization performance than wrapping it in an object with getters, but very much more readable and debuggable and less painful to write. And more performant on read.

In your thinking about performance, have you considered the performance cost of doing an extra pointer indirection every time you look up what would have been a field?

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!

Jabor posted:

In your thinking about performance, have you considered the performance cost of doing an extra pointer indirection every time you look up what would have been a field?
Yeah, that aspect sucks a bit for readability too (this.fart.smell instead of this.smell). And using an interface type means you can't even put helper functions onto the 'fart' for getting combined parameters or whatever. But if you go full object for the fart param so you can have helper-getters, the initialization process and repetition at definition-time sucks even worse (and you're still suffering from the extra indirection). :(

You can reduce the indirection significantly if you're using multiple parameters in one function, like const fart = this.fart at the start of the function, then after that rfor the rest of the function it's one-hop indirection to the sub-params which you'd have had with the member variables anyway (this.smell vs fart.smell is the same).

In Dart you can solve this sort of thing with chainable setters (fart..smell=a..visibility=b..taste=c), which you can kind of do in typescript by making setter functions that return 'this' (new Fart().setSmell(a).setVisibility(b).setTaste(c)), but, again, to do that you're requiring a shitload of boilerplate (and unlike the interface, that model also won't compile away to nothing).

roomforthetuna fucked around with this message at 01:30 on Nov 3, 2022

fuf
Sep 12, 2004

haha
Can a real programmer explain why this doesn't work and what I should do instead?

code:
function GetData() {
    API.getData(payload, function (data) {
      setData(data);
      if(continuous) {
        GetData();
      }
    });
  }
If "continuous" is true I want to immediately start a new API call when the old one finishes.

The above code works but if I change "continuous" to false it still keeps running. Like it always thinks that "continuous" is true once it starts running.

This is in a React app if that matters.

e: never mind, I figured something out using useEffect.

fuf fucked around with this message at 14:48 on Nov 9, 2022

Deadite
Aug 30, 2003

A fat guy, a watermelon, and a stack of magazines?
Family.
I'm new to react and I've been writing a class/component for a webpage but it's getting too long and hard to manage. I'd like to break the functions that create the HTML for the render function out into their own files, but I'm having trouble accomplishing this because the HTML in these newly external functions refer to functions in the class. Is there a way for an imported function to have access to the functions that already exist within the class?

For instance, say the function that I'm importing returns an HTML drop down input, and when the input is changed I'd like it to call the handleChange function that already exists in the class, which would normally just be "this.handleChange.bind(this)". Can I write the HTML to call that handleChange function?

Edit: This is close to what I want to do, but it still won't call the handleChange function, which is a function within the class. I just get this in the console: "Uncaught TypeError: Cannot read properties of undefined (reading 'handleChange')"
https://stackoverflow.com/questions/47273663/storing-react-class-functions-in-separate-files

Deadite fucked around with this message at 05:08 on Nov 14, 2022

fuf
Sep 12, 2004

haha
I might be misunderstanding because I'm new to React too but I think you just want to put your dropdown in a child component and call it from the parent. Then you can pass down any functions you want to the child.

In the render method of your parent component you would have something like:
code:
<MyDropdown handleChange={handleChange}/>

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Yep. I can't remember how to write class components (nobody uses them much any more, so if you are learning, unless you have a compelling reason to use them, don't) but basically:

JavaScript code:
// MyDropDown.js
export const MyDropDown = (props) => (
  <select onChange={props.handleChange} value={props.selected}>
   <option>butts</options>
    <option>farts</options>
    <option>dongs</options>
  </select>
);


// ParentComponent
import MyDropDown from './mydropdown';

export const ParentComponent () => {
  const [sel, setSel] = useState("butts");

   return (
     <div>
      <h1>Wow!</h1>
      <MyDropDown handleChange={setSel} selected={sel} />
      </div>
    );
};
EDIT: it feels so wrong to not use typescript....

Lumpy fucked around with this message at 00:35 on Nov 15, 2022

Deadite
Aug 30, 2003

A fat guy, a watermelon, and a stack of magazines?
Family.

fuf posted:

I might be misunderstanding because I'm new to React too but I think you just want to put your dropdown in a child component and call it from the parent. Then you can pass down any functions you want to the child.

In the render method of your parent component you would have something like:
code:
<MyDropdown handleChange={handleChange}/>

Thanks, I didn't know about parents/children and that seems to be what I was looking for. I put what I needed into props and now I can update the state the way I need to.

Lumpy posted:

Yep. I can't remember how to write class components (nobody uses them much any more, so if you are learning, unless you have a compelling reason to use them, don't) but basically:

What does this mean? Should I not be doing the parent/child/props thing? I have no idea what I'm doing so if there's a better way I'd like to learn that.

Ima Computer
Oct 28, 2007

Stop all the downloading!

Help computer.

Deadite posted:

What does this mean? Should I not be doing the parent/child/props thing? I have no idea what I'm doing so if there's a better way I'd like to learn that.

Check out the beta docs/tutorials - they use function components instead of classes, which is the way (almost) all React code is written these days.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself

Deadite posted:

What does this mean? Should I not be doing the parent/child/props thing? I have no idea what I'm doing so if there's a better way I'd like to learn that.

It just means there's two ways to write a React component, and the class component way is pretty much deprecated at this point.

Class component with state

TypeScript code:
class MyComponent extends React.Component {
    this.state = {
        someValue: ''
    }

    handleChange(e) {
        this.setState({ someValue: e.target.value})
    }

    render() {
        return (
            <div>
                <h1>{this.props.header}</h1>
                <input onChange={handleChange} value={someValue} />
            </div>
        )
    }
}
function components way of doing it

TypeScript code:
import { useState } from 'react'

const MyComponent = (props) => {
 const [someValue, updateValue] = useState('')

 const handleChange = (e) => {
    updateValue(e.target.value)
 }
 
 return (
    <div>
        <h1>{props.header}</h1>
        <input onChange={handleChange} value={someValue} />
    </div>
 )
}

teen phone cutie fucked around with this message at 01:27 on Nov 15, 2022

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
There's nothing wrong with class components and they're still valid, but there's really no reason to write them anymore because it's just more code for no benefit.

fuf
Sep 12, 2004

haha
why does everyone write functions like this now:

code:
const handleChange = (e) => {
    updateValue(e.target.value)
 }
instead of like this:
code:
function HandleChange(e){
  updateValue(e.target.value)
}
?

gbut
Mar 28, 2008

😤I put the UN🇺🇳 in 🎊FUN🎉


Arrow functions look nicer to people who like functional programming, and there are different considerations regarding the binding of this, hoisting, etc.

There's not that much difference in the end, mostly aesthetics.

go play outside Skyler
Nov 7, 2005


fuf posted:

why does everyone write functions like this now:

code:
const handleChange = (e) => {
    updateValue(e.target.value)
 }
instead of like this:
code:
function HandleChange(e){
  updateValue(e.target.value)
}
?

if you put HandleChange in a callback context, "this" will refer to the callback context with version 2. With version 1, "this" will be implicitly captured and refer to whatever it was when the function was defined.

Adbot
ADBOT LOVES YOU

MrMoo
Sep 14, 2000

fuf posted:

why does everyone write functions like this now:


Cargo cult worshiping, usually the same people believe https://standardjs.com/ is actually real.

As in people actually refuse to use the function declaration now.

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