EdwardZZZ / articles

工作点滴记录
2 stars 0 forks source link

js function 默认返回值 #9

Open EdwardZZZ opened 7 years ago

EdwardZZZ commented 7 years ago
var a = function(){
  this.a = 1;
  this.c = 6;
  // return {
  //   a: 5,
  //   b: function(){
  //     console.log('-->', this, this.c)
  //     return this.a
  //   }
  // }
  // return this;
}

a.prototype.a = 3;
a.prototype.b = 4;

console.log(a())
console.log(new a())

使用构造函数时,默认返回值是this 方法直接调用时,无返回时,返回值是undefined;有返回时,返回值是返回内容

两种返回值都可以改写