JavaScript对象添加属性和方法

function dad(){
  this.name = "123"
  this.age = 33

}
var dad1 = new dad()
var dad2 = new dad()

dad.prototype.funcd= ()=>{
  console.log("funcdddddd")
}  //通过“dad.prototype.funName”添加方法,并影响所有的实例,eg:dad1, dad2
// dad1.prototype.funce= ()=>{
//   console.log("funceeeee")
// }// 不能通过"实例对象.prototype.funName"添加方法
dad1.funcf= ()=>{
  console.log("funcffff")
}// 不能通过"实例对象.prototype.funName"添加方法

dad1.funcd()
dad2.funcd()
dad1.funcf()
// dad2.funcf()  //只有dad1有这个方法
原文地址:https://www.cnblogs.com/sunupo/p/15476156.html