JavaScript proposals - HTTP203

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ต.ค. 2024

ความคิดเห็น • 132

  • @chirag2005
    @chirag2005 6 ปีที่แล้ว +73

    Please do more videos on such TC39 proposals, this was great 👍🏼

  • @ColinRichardson
    @ColinRichardson 6 ปีที่แล้ว +12

    This is my favourite episode. It's hard to keep up with proposals in a digestible way . My favourite one was "data.something ?? default". Because "data.depth || 1" is annoying if the passed in value is zero and zero is valid.

  • @gomidefabio
    @gomidefabio 6 ปีที่แล้ว +12

    Great video! Great way to popularize proposals that are being discussed on stage 0 and 1. =) Very nice

  • @DamianMontero
    @DamianMontero 6 ปีที่แล้ว

    this was amazing. please please do more of this cause it's fascinating and EASY to share among peers as something fascinating to talk about. And you guys make EVERYTHING interesting!

  • @boem231
    @boem231 2 ปีที่แล้ว +2

    Some of these actually made it in JS!

  • @CyberAcidPlanet
    @CyberAcidPlanet 6 ปีที่แล้ว

    Loving that Javascript proposals title with a sequence of Surma laughing his socks off.

    • @dassurma
      @dassurma 6 ปีที่แล้ว +1

      I mean... some of them are _questionable_

  • @XiXora
    @XiXora 6 ปีที่แล้ว +21

    Great episode!
    const foo = bar?.baz ?? "I am looking forward to do this in JS.";

    • @ColinRichardson
      @ColinRichardson 6 ปีที่แล้ว +1

      const foo = bar?.baz?.more?.stuff ?? "another default" sounds so SO good..

  • @JimmyS2
    @JimmyS2 6 ปีที่แล้ว +1

    Object?.property/method is found in Kotlin, it's null safety check, if the object isn't null proceed with reading the property or call method. love to see it make it's way into JavaScript

  • @ramizk5465
    @ramizk5465 5 ปีที่แล้ว +4

    a[-1] would be great to get the last item, python style

  • @pawemikoajczyk6417
    @pawemikoajczyk6417 6 ปีที่แล้ว +1

    Awesome episode! You both make together such a great team. I always listen to you with pleasure. Cheers.

  • @_srhenry
    @_srhenry 3 ปีที่แล้ว +1

    Thank God this null coalescing operator is implemented now

  • @avilde
    @avilde 6 ปีที่แล้ว +1

    Coalescing null is definitely my pick too. Those extra checks make the code look longer than needed.
    Wanted to ask for quite some time:
    @Surma & @Jake, do you guys have been interviewed about your careers - 'how did you get where you are now'?

  • @viniciuscarneiro650
    @viniciuscarneiro650 6 ปีที่แล้ว +1

    Love it. Pls do more of those!

  • @deadlyhifi
    @deadlyhifi 6 ปีที่แล้ว

    Great episode. Keep us updated with the status of these proposals.

  • @jimbo2150
    @jimbo2150 6 ปีที่แล้ว

    10:32 - or arr.slice(-1), though I also like that lastItemIndex is also proposed along with it. If you want the index you have to do length-1.

  • @_akuma06
    @_akuma06 6 ปีที่แล้ว

    The question mark is really useful, I'm always using it in Kotlin. Much better and more readable than checking every property.

  • @kdelmonten
    @kdelmonten 6 ปีที่แล้ว

    Taking awesome parts from different languages. JS getting better and better!

  •  6 ปีที่แล้ว

    Great stuff. I like the buddy chat format. keep going. great, yes ,do it, ship it.

  • @rlamacraft
    @rlamacraft 6 ปีที่แล้ว +1

    This was great fun! Some great proposals… some not so much

  • @PabloNevares
    @PabloNevares 5 ปีที่แล้ว

    Surma likes optional chaining/safe navigation so much that it deserved two 3:48 "interestings" 5:03 😅

  • @pgarciacamou
    @pgarciacamou 6 ปีที่แล้ว

    Interestiiing video (the good interesting)! I agree with Surma on every single one of his reactions. This was a great video; easy to watch, great personalities, smart conversation! Keep making videos on JS new features.

  • @leonk6950
    @leonk6950 5 ปีที่แล้ว

    The someFunction(234) { /*lambda*/} thing would be useful under one condition: That it supported Kotlin-like implicit arguments. in Kotlin you can say array.filter { it > 5 }, where it automatically contains the current value. in js this would currently look like this: array.filter(it => it > 5).
    For such short Lambdas, the readability dramatically increases with Kotlins approach, so id love if this was added WITH that "it" feature

  • @hemantbhoyar4462
    @hemantbhoyar4462 6 ปีที่แล้ว

    The one with the last callback in the parameter is the function body, with some other stuff can be great to write DSLs. Don't know if javascript needs DSLs. Kotlin does it really nice though.

  • @kamoroso94
    @kamoroso94 6 ปีที่แล้ว

    I love the idea of .firstItem and .lastItem! The syntax for that do block and the syntax sugar callback thing seemed really neat too! Not mentioned in here was the pipe operator, which I can get behind :)

    • @KenBellows
      @KenBellows 6 ปีที่แล้ว

      They probably didn't include the pipeline operator because they've actually talked about it previously here: th-cam.com/video/lsd2-TCgHEs/w-d-xo.html , starting somewhere around 7min15s

  • @martixy2
    @martixy2 6 ปีที่แล้ว +4

    At least 7:45 should have already been in there(it exists in a number of languages, c# and php to name a few, and is called the null-coalescing operator). Most others are... iffy.
    Also, forget last item, give us negative indices.
    And null coalescing isn't hard to librarify. See brototype.

    • @jakearchibald
      @jakearchibald 6 ปีที่แล้ว +1

      See the other comments - negative indices isn't compatible with existing JavaScript

    • @daslafdev
      @daslafdev 6 ปีที่แล้ว +1

      Negative indices would break stuff like this:
      const val = [1,2,3].findIndex(i => i === 4) // -1

    • @ColinRichardson
      @ColinRichardson 6 ปีที่แล้ว

      Not to mention `array["-1"] = "not last element"; `

    • @daslafdev
      @daslafdev 6 ปีที่แล้ว +1

      I guess he was asking for negative indices to behave like in `[1, 2, 3].slice(-1)[0] // 3`

    • @martixy2
      @martixy2 6 ปีที่แล้ว

      The concept isn't bloody rocket science! It already exists in so many other languages. Just nick it from there. It fundamentally CANNOT be incompatible with JS.

  • @DenisTRUFFAUT
    @DenisTRUFFAUT 6 ปีที่แล้ว +1

    I think the null coalescent operator ?? should be shipped with the short ternary operator ?: (PHP has both)
    Otherwise, I do love the syntax ?. it will be extremely convenient for accessing JSON structures.

  • @EthanStandel
    @EthanStandel 6 ปีที่แล้ว

    To echo other opinions, this has been really awesome and the most simple explanation of new language principles. Also, firstItem? You could literally just do:
    const [firstItem] = arr;
    But I suppose there's no clean setter for it.

  • @sobanya_228
    @sobanya_228 6 ปีที่แล้ว

    Can't find trailing closure proposal. How is it called?

  • @DrewMiller1
    @DrewMiller1 6 ปีที่แล้ว

    ?. makes it easier to access fields off objects where we don't know what the object looks like, but do we really want to be doing that? Write a function to validate input or fill default values instead. One reason PHP is hard to read is that $v=$a[3][5]; doesn't throw even when there is no $a[3] so $v can go on to cause problems much later. People will learn to only use ?. because it doesn't exception, but there should be an exception to keep the bug local.

  • @OkKillionaire
    @OkKillionaire 6 ปีที่แล้ว

    Can you include the proposal numbers next time? Or perhaps a link to the gihub repo?

    • @jakearchibald
      @jakearchibald 6 ปีที่แล้ว

      They're all listed at github.com/tc39/proposals

  • @SlayMaster3000
    @SlayMaster3000 6 ปีที่แล้ว +2

    One idea I had was to add `pure` as a keyword that can be used before function definitions.
    This would allow JS engines to optimise pure function really easily without having to worry about the possibility of side effects.
    Additionally, linters and other JS processing tools could better analyse these function and do things that they otherwise couldn't.
    (functions declared as pure would be enforced to be pure i.e. they would have restrictions on what they could do - e.g. they can't cause side effects or call non-pure functions)

  • @yoavsarfaty8162
    @yoavsarfaty8162 6 ปีที่แล้ว

    why not backwards array indexing like in python? (arr[-1] returns the last item)

  • @ELStalky
    @ELStalky 5 ปีที่แล้ว

    Last array item is easy: arr.reverse()[0] 😜
    I am against that shorthand for providing callbacks. It unnecessarily complicates the syntax; anonymous functions are already really concise via arrow functions (unlike in certain other languages like e.g. Python where they use the "lambda" keyword).

  • @GmoneyMozart
    @GmoneyMozart 6 ปีที่แล้ว

    This show is like Mr. Rogers for programmers lol an epic channel 13 programming special!

  • @rezguibahaeddinne1605
    @rezguibahaeddinne1605 6 ปีที่แล้ว

    Thank you guys so much

  • @GreenZ3r0
    @GreenZ3r0 6 ปีที่แล้ว +1

    I love the most of this proposals. |> and :: are very nice operators too. Love your 203 series. Liebe Grüße aus Deutschland

    • @jakearchibald
      @jakearchibald 6 ปีที่แล้ว +1

      We've done a whole video on |> and :: m.th-cam.com/video/lsd2-TCgHEs/w-d-xo.html

  • @briangradin4462
    @briangradin4462 6 ปีที่แล้ว

    I believe in C# the ?. operator is called the null conditional operator, and the null coalescing operator is something else entirely (??). Is JS really going to mix up those ideas?
    Edit: watched further and realized you mentioned the ?? operator, but you didn't name it. What is it called?

    • @dassurma
      @dassurma 6 ปีที่แล้ว

      We probably mixed it up! SO we are to blame. Looking it up .? is called “nullish coalescing” in the proposal.

  • @yuyokk
    @yuyokk 6 ปีที่แล้ว +1

    Thanks for the informative video!

  • @romaindurand
    @romaindurand 6 ปีที่แล้ว +1

    The new syntax for callbacks looks weird, way too similar to a function definition imho ...

    • @XanderLuciano
      @XanderLuciano 6 ปีที่แล้ว

      Agreed, that would really confuse me upon first encounter if I didn't know what it did.

  • @gualaguala
    @gualaguala 6 ปีที่แล้ว

    Guys I love your cup-holder :D hello from Denmark!

  • @wrod7
    @wrod7 6 ปีที่แล้ว

    exciting stuff. does typescript have these already?

    • @daslafdev
      @daslafdev 6 ปีที่แล้ว

      the null safe operator, yes... I don't know about `?? ` or the other ones

  • @BennyPowers
    @BennyPowers 6 ปีที่แล้ว

    code ideas for next time: function composition.

    • @BennyPowers
      @BennyPowers 6 ปีที่แล้ว

      also, web components

  • @malipetek
    @malipetek 5 ปีที่แล้ว

    second one is great

  • @feldinho
    @feldinho 6 ปีที่แล้ว

    Idk… `const last = xs => xs[xs.length - 1]` is easy enough to have in some kind of utils file!
    The setter is interesting, though.

    • @KenBellows
      @KenBellows 6 ปีที่แล้ว

      yeah but what's cleaner, `arr.lastItem` or `const {lastItem} = require('utils'); lastItem(arr)`? All the array prototype methods (map, reduce, filter, etc) are also trivially easy to write in a util library (see lodash), but including features like this natively means that you don't have to ship that code to the browser, you can reduce dependency on 3rd party libs, and perhaps most importantly browser engines can do work to optimize the crap out of them

  • @sajankhandelwal8570
    @sajankhandelwal8570 6 ปีที่แล้ว

    Thanks for the video.

  • @mariusdelport
    @mariusdelport 6 ปีที่แล้ว

    very good thank you

  • @leonnilein
    @leonnilein 6 ปีที่แล้ว

    A lot of that reminds me of Kotlin. Nice stuff, looking forward to having that in JS.

  • @aarjithnandakumar
    @aarjithnandakumar 6 ปีที่แล้ว

    Great video. Jake reminds me of Sheldon :)

  • @welltypedwitch
    @welltypedwitch 5 ปีที่แล้ว

    9:06 oh... :/ I got excited because I thought this was that pattern matching function declaration thingy from haskell (Where you can say
    fact 0 = 1
    fact x = x * fact(x - 1)

  • @EdigleyssonSilva
    @EdigleyssonSilva 6 ปีที่แล้ว

    Awesome!

  • @jincyquones
    @jincyquones 6 ปีที่แล้ว

    FINALLY, JS will have a null conditional operator!! Praise ECMA!

  • @JamesFreeman
    @JamesFreeman 6 ปีที่แล้ว +1

    Why have arr.lastItem? Just do arr[-1]

    • @jakearchibald
      @jakearchibald 6 ปีที่แล้ว

      See the other comments - that wouldn't be compatible with existing JavaScript

  • @JoseJavierEspinoza
    @JoseJavierEspinoza 6 ปีที่แล้ว +1

    The best is const something = config.someAttr?.length ... I need something like that

  • @trolledwoods377
    @trolledwoods377 6 ปีที่แล้ว

    pythons negative indexing is way better than last item

  • @josephbon
    @josephbon 6 ปีที่แล้ว

    That's a Pixel C! I miss mine :(

  •  6 ปีที่แล้ว

    TIL holey arrays

  • @dragannovakovic9816
    @dragannovakovic9816 6 ปีที่แล้ว

    what about Pattern Matching ?

    • @dassurma
      @dassurma 6 ปีที่แล้ว

      There is actually a proposal for this: github.com/tc39/proposal-pattern-matching

  • @krawieck
    @krawieck 6 ปีที่แล้ว

    Why can't it instead of arr.lastItem be arr[-1] ?

    • @dassurma
      @dassurma 6 ปีที่แล้ว +1

      Because you can actually have `-1` as a key :D

    • @jakearchibald
      @jakearchibald 6 ปีที่แล้ว +1

      I agree it should have been that, but there's too much code in the wild accidentally using negative indexes, and changing the behaviour there would break lots of stuff.

    • @krawieck
      @krawieck 6 ปีที่แล้ว

      Oh... That's unfortunate :(

  • @b3rakesh11
    @b3rakesh11 6 ปีที่แล้ว

    Awesome

  • @tsortanidischristos412
    @tsortanidischristos412 6 ปีที่แล้ว

    Hmm ok I'm reaaally waiting for this photos?.length

  • @panosarvanitis8109
    @panosarvanitis8109 6 ปีที่แล้ว

    please do it again.. 6:39 :) @Surma

  • @vlad981
    @vlad981 6 ปีที่แล้ว

    cool video)
    How could you not mention |> (pipeline operator) ? :))

    • @dassurma
      @dassurma 6 ปีที่แล้ว +2

      Because we already talked about it in the tree-shaking video: th-cam.com/video/lsd2-TCgHEs/w-d-xo.html

  • @TheChodex
    @TheChodex 6 ปีที่แล้ว

    Is it me or is JavaScript becoming more and more like C#? Stuff like ?. ?? (aka nullable operators), arrow function syntax etc. all seem pretty familiar... :P :D

    • @KenBellows
      @KenBellows 6 ปีที่แล้ว +1

      Maybe more generally, lots of languages are starting to integrate features from others. C# wasn't the first to have lambdas (which is really what arrow functions are), null coalescing, under-the-hood getter and setter functions, etc. C# learned a lot from other languages, and now JS is learning form others as well, including C# for sure.

  • @MindfulMinun
    @MindfulMinun 6 ปีที่แล้ว

    Smells like CoffeeScript. The good kind.

  • @adithyareddy6211
    @adithyareddy6211 6 ปีที่แล้ว

    It'd be so much better if we could get arr[-1] like in Python instead of arr.lastItem

    • @dassurma
      @dassurma 6 ปีที่แล้ว +2

      The problem is that x[-1] is actually valid. It could break existing code.

    • @adithyareddy6211
      @adithyareddy6211 6 ปีที่แล้ว

      @@dassurma there's always a catch 🙆‍♂️. Thanks!

    • @JamesFreeman
      @JamesFreeman 6 ปีที่แล้ว

      I use arr[-1] in my prod code when parsing url's split on / it's not just Python, it's already js

  • @XerosXIII
    @XerosXIII 6 ปีที่แล้ว

    srsly... JS getting more and more cryptic as the years goes by :

    • @ColinRichardson
      @ColinRichardson 6 ปีที่แล้ว +1

      says the guy using :< which is one I have never seen before.. lol

  • @DanVC
    @DanVC 6 ปีที่แล้ว

    Is this guy from left side just a Javascript programmer? I mean.. all these proposals are stuffs that already happens in many other languages.

    • @dassurma
      @dassurma 6 ปีที่แล้ว +4

      You mean the guy that said “Oh that’s so ruby”?

    • @DanVC
      @DanVC 6 ปีที่แล้ว

      Phew... exactly Suma.. Interesting 😘

  • @childishalbino9548
    @childishalbino9548 3 ปีที่แล้ว

    Array.lastItem is so unnecessary IMO. What’s wrong with array[-1] or for that matter array[-N] like python has it. So much more powerful and less prescriptive

    • @jakearchibald
      @jakearchibald 3 ปีที่แล้ว

      Agreed, but it isn't backwards compatible to add it now.

    • @childishalbino9548
      @childishalbino9548 3 ปีที่แล้ว

      @@jakearchibald oh no! I didn’t think of that... that’s really sad :( maybe instead there could be a method that achieves the same effect like Array.fromLastIndex(index)...? I suppose this wouldn’t work for setting though which would be a shame

  • @martinfreire6733
    @martinfreire6733 6 ปีที่แล้ว

    +10 to null coalescing operator
    +10 to lastIem
    +1 to replaceAll
    +1 to ??
    0 don't care about "do" block
    -100 to the function shorter.

    • @ColinRichardson
      @ColinRichardson 6 ปีที่แล้ว

      Yes, Function shorter can be dropped.. but `.replaceAll` needs to be in... NOW....

  • @mathiasbynens1518
    @mathiasbynens1518 6 ปีที่แล้ว

    10:01 😂

  • @jayankaghosh
    @jayankaghosh 6 ปีที่แล้ว

    The language of the future

  • @kalleguld
    @kalleguld 6 ปีที่แล้ว

    Interesting

  • @jimbo2150
    @jimbo2150 6 ปีที่แล้ว

    The ? and ?? syntax along with the Array.lastItem and Array.lastItemIndex additions I support. For Promise.try it looks interesting but can't think of somewhere it would be useful off the top of my head. String.replaceAll - Yes.
    I'm againts do{} block. It only removes a few characters of length and removes the ability to apply parameters. New syntax (why not return a value like any other function block?) and not enough goodness in my opinion.
    Finally, JUST SAY NO to Ruby syntax! Using a second parameter outside the function parentheses is just confusing and unnessary - as stated in the video, there is almost nothing different between the two syntaxes except for the fact that the first likely prevents other parameters from being added (not sure how that would be handled) and is confusing to those who are not Reactor/Ruby developers.

  •  6 ปีที่แล้ว

    so, I 'learned' that async IIFEs exist!! my life is a lie, I barely use IFFEs, now I have to research when to use async IFFE. now I just feel dumb. Especially the way the dude shrugs them off like they're garden-variety functions 😎🚬. where can I read up on them?

  • @bjlbernal
    @bjlbernal 6 ปีที่แล้ว

    Promise.try()
    ===> No, since IIFE does the same thing, what value is really added.
    const val = data.photos?.length;
    ===> Really? JS would be better if it just returned the undefined of 'photos' instead of throwing a halting error that 'length' is being called/executed on an undefined. If the parent is undefined, then the presumed child is inherently, also. Why doesn't JS just return the parent undefined? Any rendering code will still have to check if val is not undefined before using it so it can default to something else.
    const state = do {
    if (banned()) 'banned';
    elseif (loggedIn()) 'loggedin';
    else 'loggedout';
    };
    ===> So this is needed only if writing JSX? Because the IIFE doesn't work in JSX? Sounds like a different solution is needed.
    const val = hello.world ?? 'default'
    ===> Yes, but this also brings me back to `const val = data.photos?.length;`. If it was `hello.world.tree` and `world` is undefined, then `tree` will throw an error first. Calling a child on an undefined parent needs to first just return the undefined.
    const val = queryString.replaceAll('+', ' ');
    ===> Yes, but I'd just rather .replace() be given an optional third parameter that told it to do ALL instances.
    somefunction(255) {
    console.log('hello');
    }
    ===> No, this syntax sugar adds barely anything.
    console.log(arr.lastItem)
    arr.lastItem = 4
    ===> Yes, I've thought about it some more and I accept the usefulness of this since it is also a setter.

    • @XanderLuciano
      @XanderLuciano 6 ปีที่แล้ว +1

      IIFE's are not immediately obvious when they span across multiple lines. Promise.try()'s value is better readability.
      data.photos?.length offers many more advantages such as chaining like data.property?.someFunction(). which could easily remove multiple if statements in exchange for shorter, easy to read code.
      Again, IIFE's suck when they are over multiple lines. I'm not a fan of the 'do' syntax, but I can see it's advantage.
      You're completely missing the advantage of setting a default value and focusing on a single use case.
      I think .replaceAll is much clearer than a third argument. Read: "Replace All Arg1 with Arge 2" vs "Replace Arg1 with Arg2. All Places?" replaceAll is much clearer, and only 3 extra characters.
      Agreed, I think this actually makes it much harder to read and understand.
      This one seems helpful occasionally, but otherwise I'm indifferent on the matter.

  • @AnaGabrielPerez
    @AnaGabrielPerez 6 ปีที่แล้ว +4

    plz video with your new kitten

    • @jakearchibald
      @jakearchibald 6 ปีที่แล้ว +4

      Not a video but: photos.app.goo.gl/GjATXtV7yDmbsStS8

    •  6 ปีที่แล้ว

      lol ! he's cute. He's not named Salem is he?

  • @MinusTechTips
    @MinusTechTips 6 ปีที่แล้ว

    that one dislike is from a PHP developer

  • @gilbarbara
    @gilbarbara 6 ปีที่แล้ว +1

    mimimi! 🤣

  • @promatik
    @promatik 6 ปีที่แล้ว +2

    Didn't like this one: data.photos?.length it should be handled like the coalescing one, data.photos.lenght ?? 0;

    • @floverdevel
      @floverdevel 6 ปีที่แล้ว +1

      Yes just like in PHP :)

    • @dassurma
      @dassurma 6 ปีที่แล้ว +1

      `data.photos.length` throws if `photo` is undefined. `data.photos?.length` would not.

    • @promatik
      @promatik 6 ปีที่แล้ว +1

      In PHP `data.photos.length ?? 0` will return 0 if photos or even data is undefined, I think it's much easier.

    • @ColinRichardson
      @ColinRichardson 6 ปีที่แล้ว

      So
      `const a = data.photos.morelevels.evenmore.whynot.length ?? 0` is
      `
      let temp;
      try { temp = data.photos.morelevels.evenmore.whynot.length; }
      catch ( err ) { temp = 0; }
      const a = temp;
      `

    • @dassurma
      @dassurma 6 ปีที่แล้ว +1

      No, `??` doesn’t catch any errors, it only gives a robust version of a default value `.?` kinda catches errors, but only property access related ones.

  • @JustBenInLA
    @JustBenInLA 6 ปีที่แล้ว

    I would like to propose the death of JavaScript!

    • @dassurma
      @dassurma 6 ปีที่แล้ว

      We are just getting started, mate ;)