JS-- 小细节--你悟到了什么?

var p = {
// x and y are regular read-write data properties.
x: 1.0,
y: 1.0,

r:function () { return Math.sqrt( x*x + y*y); },

};

如果调用 p.r(),会报错的, r函数里面必须要用 this来引用 x和y。你悟到了什么呢?

 

posted @ 2017-09-30 15:09  流畅的心情  阅读(230)  评论(2)    收藏  举报