`
keren
  • 浏览: 1573791 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

为什么要使用“var me=this”这样的写法

 
阅读更多
http://www.mhzg.net/a/20139/2013941150702.html
只为压缩。
function doA() {
    var me = this;
    
    me.a();
    me.b();
    me.c();
    me.d();
}
function doB() {
    this.a();
    this.b();
    this.c();
    this.d();
}

压缩后:
function doA(){var a=this;a.a();a.b();a.c();a.d()};
function doB(){this.a();this.b();this.c();this.d()};
分享到:
评论

相关推荐

    微信小程序开发中var that =this的用法详解

    在微信小程序开发中,var that =this的声明很常见。举个例子,代码如下! 示例代码1 //index.js Page({ data: { toastHidden: true, }, loadData: function () { var that = this//这里声明了that;将this...

    浅析JavaScript中var that=this

    在阅读别人的代码时,发现别人写的代码中有这么一句:var that = this;,这代表什么意思呢?经过一番查阅,才明白是这么回事。 在JavaScript中,this代表的是当前对象。 var that=this就是将当前的this对象复制一份...

    微信小程序中为什么使用var that=this

    在微信小程序或JavaScript开发中,`var that = this` 的使用常常被用来保存函数外部的上下文引用,尤其是在处理异步操作、事件处理或者在闭包中时。这个做法可以帮助开发者确保在函数内部仍然能够访问到正确的 `this...

    微信小程序开发中 var that =this的用法

    在微信小程序开发中,var that =this的声明很常见。举个例子,代码如下! 示例代码1 1 //index.js 2 Page({ 3 4 data: { 5 toastHidden: true, 6 }, 7 8 loadData: function () { 9 var that = this//这里...

    var r = this.onTimeout(this.duration, this);解决方法

    这版本的AjaxPro.net框架集解决了出现this.onTimeout is not a function的错误,也是经常出现的"缺少对象的错误",同时包括AjaxPro.dll,AjaxPro.2.dll,AjaxPro.JSON.dll, AjaxPro.JSON.2.dll

    jquery需要的所有js文件

    this.element.bind("remove."+this.widgetName,function(){d.destroy()}),this._create(),this._trigger("create"),this._init()},_getCreateOptions:function(){return a.metadata&&a.metadata.get(this.element[0]...

    出现问题a is defined高手帮忙

    var me = this; var mapDiv = map.getContainer(); // Create div for both buttons var buttonContainerDiv = document.createElement("div"); DragZoomUtil.style([buttonContainerDiv], {cursor: '...

    抖音小程序-大转盘抽奖功能-网页传值功能-抖音私信聊天打电话功能

    var that = this var awardIndex = Math.random() * 12 >>> 0; //12个号码随机数 // 获取奖品配置 var awardsConfig = app.awardsConfig var jsq = this.data.Number - 1; //计算次数 console.log(jsq) ...

    微信小程序-微信小程序之Canvas

    var that = this var p10= data[0][0]; /* 三阶贝塞尔曲线起点坐标值*/ var p11= data[0][1]; /* 三阶贝塞尔曲线第一个控制点坐标值*/ var p12= data[0][2]; /* 三阶贝塞尔曲线第二个控制点坐标值*/ var p13= ...

    H5 Canvas炫酷3D线条延伸动画特效.zip

    var c = document.getElementById('c'); var ctx = c.getContext('2d'); var w = c.width = window.innerWidth; var h = c.height = window.innerHeight; var cx = w / 2; var cy = h / 2; var fl = ...

    this的用法以及改变this指向

    #### 为什么学习this? 在JavaScript中,`this`关键字的使用极为广泛。理解并掌握`this`的工作机制对于提高编程能力至关重要: 1. **阅读代码的能力**:不了解`this`的工作原理,将很难读懂其他人的代码或复杂的...

    js滚动图片广告写法

    var p = CurrentStyle(this._container).position; if (p !== "relative" && p !== "absolute") { this._container.style.position = "relative"; } this._container.style.overflow = "hidden"; this._slider...

    JS绿色自行车行驶动画特效.zip

    this.getAttribute("data-r") "," this.getAttribute("data-g") "," this.getAttribute("data-b") "," "1)"; colorObj.r=this.getAttribute("data-r"); colorObj.g=this.getAttribute("data-g"); colorObj.b=...

    crypto-js for egret(白鹭).zip

    AES 加密 , crypto-js 库 egret (白鹭引擎) 可以直接引用。 适合H5 egret 白鹭开发者。 亲测可用! 使用的话,用 bin 目录里面的... var decryptedStr = this.AESDecode(data,key,iv); return decryptedStr; }

    什么是this

    在上面的例子中,我们使用call方法将obj.fun函数的this值临时替换为obj2对象。 使用bind绑定this 我们可以使用bind方法基于一个函数创建一个新函数,同时提前绑定this值。例如: ``` var obj = { ename: "eric",...

    c# object, dynamic, var的区别用例

    // object, dynamic, var的区别用例 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { public string param = ...

    css3 HTML5 Canvas炫酷3D线条延伸动画特效.zip

    var pp = new P(this.x, this.y, this.z); pp.cl = this.cl; this.list.push(pp); } } else { var pp = this.list.shift(); pp.x = this.x; pp.y = this.y; pp.z = this.z; pp.cl = this.cl; ...

Global site tag (gtag.js) - Google Analytics