I reviewed it myself.
For details, please see the previous blog, click here .
About polymorphism:
As we all know, in other languages such as c, c++, csharp, java, etc., in addition to encapsulation, inheritance, there is also a polymorphism.
Although js does not emphasize this, it is still possible to realize this function in disguise. It is very simple and can be understood at a glance.
var objadd = function () {}; objadd.prototype.add = function () { var arg = arguments, len = arg.length; switch( len ){ // no parameters case 0: return 10; case 1: return 10 + arg[0]; case 2: return arg [0] + arg [1]; // etc } }; var obj = new objadd(); console.log( obj.add() ); console.log( obj.add( 1 ) ); console.log( obj.add( 10 ,15 ) );