How to mount a method to the prototype of a Date () instance in vue?

< H1 > created a Date () instance an in vue. I want to mount a method b on the instance so that var month = a.getMonth () + 1; I can call the b method < / H1 > through month.b ()

Code is:

   var a = new Date();
   a.prototype = {
       b: function () {
           console.log("111111");
           }
           }
     var month = a.getMonth();
     month.b();

but the grammar does not pass, may I ask why? In the Vue project

Nov.30,2021

a.getMonth () returns a number. How to call the method? your syntax is not correct. It has nothing to do with vue.


instance does not have a prototype. The constructor
should be posted on Date.prototype


.

a.prototype = xxxx

Change

to

Date.prototype = xxxx


should be posted on Date.prototype
and it is not recommended to modify the built-in prototype

Menu