Git Product home page Git Product logo

Comments (14)

meetsCode avatar meetsCode commented on May 28, 2024 2

look! I find one:

class Pet {
  constructor(sound) {
    this.sound = sound;
  }
}
class Dog extends Pet { 
	constructor (sound){
    super(sound);
  }
}
const aDog = new Dog('au') ;
aDog instanceof Dog ; //-> true
aDog instanceof Pet ; //-> true

Object.getPrototypeOf( Dog ) ; //-> class Pet
const aPet = new (Object.getPrototypeOf( Dog ))

aPet instanceof Dog ; //-> false
aPet instanceof Pet ; //-> true

from dmitripavlutin.com-comments.

codellyson avatar codellyson commented on May 28, 2024 1

Great post as always.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Comment written by Felix Sanz on 01/16/2020 17:37:32

I don't understand the example in section 5.2. Can't you just do if (this.name === '') { ?? If the property is inherited, why calling super on the method?

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Comment written by Dmitri Pavlutin on 01/16/2020 19:29:56

The chapter explains the method overriding.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Comment written by Felix Sanz on 01/16/2020 20:31:54

But your example is not overriding nothing at all because the inherited method is so dummy, right? It would make more sense if the parent method contains some code, not just return the property (because the property was accesible without calling super on the method anyway). I'm right?

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Comment written by Dmitri Pavlutin on 01/16/2020 20:45:04

The method overriding enhances the parent method (simple or not it does not matter) by providing a default value if the returned value is an empty string.
That’s a simple demo, don’t expect enterprise level code. 😜

Anyways, if you know a better sample, feel free to create a pull request for the post.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Comment written by igor thetigor on 02/17/2020 23:56:37

Dmitri, thank you so much for all your posts. Really good work, absolutely worthwhile. props!

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Comment written by Dmitri Pavlutin on 02/18/2020 08:36:03

Thanks!

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Comment written by Nayaka Yoga Pradipta on 07/29/2020 13:54:40

Thank you so much. Your article is easy to understand!
But do you have reference small project example that uses JS class?

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Comment written by Dagg on 10/14/2020 21:20:39

Class is actually a function, it is a syntactic sugar for a function constructor. And function constructor is a way to generate objects.

Prototypal inheritance is something different, it creates object literals via Object.create() from another object that acts as a prototype of a newly created object. So class is not generated via prototypal inheritance. Thanks

from dmitripavlutin.com-comments.

RaudelWeb avatar RaudelWeb commented on May 28, 2024

So, how should a class method be added after the class declaration?

from dmitripavlutin.com-comments.

meetsCode avatar meetsCode commented on May 28, 2024

Thanks for this great article. I miss two methods in this guide that may not yet exist in JavaScript. First a method that answers how many subclasses a class has. Second, the opposite: a method that reports what the superclass is.
Example:

class Foo(object): pass
class Bar(Foo): pass
class Baz(Foo): pass
class Bing(Bar): pass
print([cls.__name__ for cls in Foo.__subclasses__()])
# ['Bar', 'Baz']
for cls in Foo.__subclasses__():
    print(cls.__base__)
# <class '__main__.Foo'>
# <class '__main__.Foo'>

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Thanks for this great article.

@meetsCode You're welcome! πŸ˜„

I miss two methods in this guide that may not yet exist in JavaScript. First a method that answers how many subclasses a class has. Second, the opposite: a method that reports what the superclass is.

This can be useful, however, I'd rather not include these into the post.

from dmitripavlutin.com-comments.

RedEyePilot avatar RedEyePilot commented on May 28, 2024

Hi, can you please provide cases where private fields are useful?
The second question, if I create a page object model (not on Cypress) does it make sense to use private fields to protect selectors?

from dmitripavlutin.com-comments.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.