Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overloading vs overriding in javascript

In a recent JavaScript interview I was asked about overloading vs overriding. I know this is a concept in Java. But is there something similar in JavaScript, and if so what would be code examples? My understanding is that overloading isn't common in javascript. Why would you need to use "overloading" in JS?

OverRiding is a bit clearer to me - an example of over riding would be in subclassing where you are inheriting from a super class but over riding some methods/properties to create unique ones for a sub class.

like image 843
devdropper87 Avatar asked Dec 17 '15 14:12

devdropper87


1 Answers

JavaScript does not support overloading.

JavaScript supports overriding, so if you define two functions with the same name, the last one defined will override the previously defined version and every time a call will be made to the function, the last defined one will get executed.

more read here http://blog.mastykarz.nl/overloading-functions-javascript/

like image 86
Rajveer gangwar Avatar answered Sep 17 '22 10:09

Rajveer gangwar