JavaScript Best Practices - Using Prototypes

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

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

  • @twrkhanasparukh
    @twrkhanasparukh 6 ปีที่แล้ว +11

    Its worth mentioning that you are using factory pattern for object creation here. There are also constructor, prototype and dynamic prototype patterns.

  • @TheStevieharris
    @TheStevieharris 5 ปีที่แล้ว +10

    when you think your finding your feet in programming and find a video like this. well explained and kinda understood, but forgotten all ready :p

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

      Such video should be watched after knowing concepts of the IIFE and the scopes, execution content, variable environment, and things like that after practicing those things so that it makes clear sense to grasp the concept described in this video.

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

    7:22 If you want to make the code even more wierd, you can return the person object directly, by changing row: 8 to this:
    *_return_*_ person = Object.create(personPrototype, {_
    And remove the _return person;_ statement on row:15

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

    You should go over setting prototypes directly on objects, and that vs how you did it here.

  • @maker_aleks
    @maker_aleks 4 ปีที่แล้ว +1

    Why not to use class PersonFactory () { ... } which is way more elegant than IIFE?

  • @michealhall7776
    @michealhall7776 5 ปีที่แล้ว +1

    Thanks this is what I have been looking for

  • @HenrryPires
    @HenrryPires 4 ปีที่แล้ว

    Good video, i just learned something new

  • @FatsFalafel
    @FatsFalafel 4 ปีที่แล้ว +3

    I thought classes are built to take care of this issue?

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

    Very very good. Very straight forward, thanks!

  • @EnzoAuditore
    @EnzoAuditore 2 ปีที่แล้ว

    Thanks mate.

  • @ChhongMengly
    @ChhongMengly 4 ปีที่แล้ว

    Nice video sharing

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

    Thank you mam

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

    I like to create modules with all static functions, with one of them being a special "constructor" function for creating instance objects that the module works with. Then I just pass those instance objects as an argument to any static function that needs to work with instance data. So there's just one static version of all functions and simple data-only objects, without having to mess with ugly Object.prototype.whatever code.

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

      Singleton pattern

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

      @@jboxy seems like a good idea. I've never used a singleton pattern, but I'll just assume it'll work out.

    • @jboxy
      @jboxy 5 ปีที่แล้ว +1

      @@omg_look_behind_you it's almost exactly what you're doing or very close to doing :P

  • @2dabang
    @2dabang 5 ปีที่แล้ว

    So, the only way to access johnDoe's greet() method is via another person object "janeSmith". That seems weird. I want to call greet() method as johnDoe.greet() and it should printout "john". That is more natural.

    • @MadBunnyRabbit
      @MadBunnyRabbit 5 ปีที่แล้ว +1

      just use Classes instead. That's why they have been introduced in ES6.

    • @SirusStarTV
      @SirusStarTV 4 ปีที่แล้ว

      Instead of person argument he should have been used this keyword.

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

    Shouldn't the call operator "()" be within the embracing parenthesis? I feel that it would build a tighter bound between the anonymous function and its invocation in a single, ephemeral expression...

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

    Sweet. Love programming

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

    what basically he did is he converted the greet method into a singleton, so whenever any person object is create they will all share the same greet method

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

    Excellent

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

    Brilliant

  • @NoajmIsMyName
    @NoajmIsMyName 4 ปีที่แล้ว

    I'm confused... Why is it True again ?

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

      Before the factory would create its own function and stored it in memory. So everytime you created a new person a new function was also created. The thing is we want to just reuse one of those functions for all of the person's we create. So this made it so only one is created and when he tests it with === he could see that both person's created were using the same function instead of their own unique version of the function.

  • @jsnode2075
    @jsnode2075 7 ปีที่แล้ว

    What is the name of the extension to live preview on dev tool?

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

      That's developer tools, try Node REPL it's easy

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

    Wow... Is this 2010?

  • @frankvee
    @frankvee 5 ปีที่แล้ว +3

    Oh my head hurts. lol

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

      just use Classes instead. That's why they have been introduced in ES6.

  • @karthickdurai2157
    @karthickdurai2157 4 ปีที่แล้ว +1

    Couldn't understand, he's complicating it

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

    my brain hurts

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

      happens

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

      just use Classes instead. That's why they have been introduced in ES6.

  • @赵三三弟
    @赵三三弟 6 ปีที่แล้ว +2

    看起来不太刺激

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

    Um... ES6 anybody? Classes? Hello? What is this bullshit?!