this关键字

在javascript中,必须为属性显式的指定this关键字 。  写成 return this.width*this.height

如果觉得必须在每个实例字段前都使用this前缀很不好看,那么可以在自己的每个方法中使用with语句

Rectangle.prototype.area = function() {
      with(this){
         return width*height;
      }
}

 

参考文章】

http://www.quirksmode.org/js/this.html

http://www.cnblogs.com/georgewing/archive/2009/09/29/1576641.html

------------------------------------------------------------------------------------------------------

原文地址:https://www.cnblogs.com/yingzi/p/2582626.html