0

I am from c++ background and I am learning javaScript now. I having trouble understanding polymorphism from javScript's perspective. I understand what is polymorphism how is it implemented i c++ and how it is implemented in javaScript

Polymorphism : Objects of different types responding to method calls at run time, where user is not aware of the type of the object.

Implementation in c++ : We create a base pointer and assign derived class's object to it and then we make a function call using that pointer.:

Implementation in javaScript : we create a function in main function object then we create another function with same name in a function object inherited from the main function object and add them in an array and then execute that array

My doubt is in javaScript we are not making the call based on the parent object. I mean like we have base pointer in c++ and using that we are making the specific function call. I am not sure if I could make myself clear , but would be really thankful if someone could help me

1

1 Answer 1

0

C++ is "class based" OOP, while JS is "prototype based" OOP. Moreover, JS is a functional programming language (ref: comment of @Cheers and hth.)

That is why they are different. When you have knowledge of prototype based OOP, you will understand

There is a book called "Secrets of the JavaScript Ninja", I learn JS a lot from that.

Sign up to request clarification or add additional context in comments.

6 Comments

"JS is a functional programming language", no, it's not.
I'm not sure what you're trying to express. A functional language is based on the idea of immutable state. JavaScript (and C++) is based on mutating state, that is, assignments. You can do functional programming or at least functional style programming in both JavaScript and C++ but JavaScript supports that better. I find some dicussion of funcional programming in JavaScript in Wikipedia, at (en.wikipedia.org/wiki/…).
Thanks, may I update my post with reference to your comment. I think your comment explains the "functional stuff" better than me
Of course, but I'm still not sure what you were trying to say. :)=
None of the comments clarified my doubt
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.