在vue中创建了一个Date()实例a,我想在实例上挂载一个方法b,使var month = a.getMonth()+1;能通过month.b()来调用b方法
代码为:
var a = new Date();
a.prototype = {
b: function () {
console.log('111111');
}
}
var month = a.getMonth();
month.b();
但是语法不通过,请问这是为什么呢?在Vue项目中
实例是没有原型的,构造函数才有原型
应该挂到 Date.prototype上