将此作为基础对象的上下文保留在javascript对象的属性中

时间:2016-04-19 18:33:41

标签: javascript object

我想知道在java脚本对象的子属性中维护一种(var self = this)耦合需要做些什么。例如,如果我有以下对象:

var canvas = document.getElementById('GameCanvas');
var ctx = canvas.getContext("2d");

var asset = card.asset;

// set the card height based off the width
var height = width * 2.66;

// save the canvas before rotating
ctx.save();

// hover effect for drawn card
if (core.information.xoffset >= left && core.information.xoffset <= left + width && core.information.yoffset >= top && core.information.yoffset <= top + height) {

    ctx.shadowColor = 'white';
    ctx.shadowBlur = 15;

}

// translate to the center of the card
ctx.translate(core.information.pwidth * (left + width/2), core.information.pheight * (top + height/2));

// rotate the canvas for the card
ctx.rotate(rotation * Math.PI/180);

// translate back
ctx.translate(-core.information.pwidth * (left + width/2), -core.information.pheight * (top + height/2));

// draw the card
ctx.drawImage(asset, core.information.pwidth * left, core.information.pheight * top, core.information.pwidth * width, core.information.pheight * height);

// restore the canvas after rotating    
ctx.restore();

根据我目前的理解,当在对象中时,如果它是对象的属性,则该引用直接传递给函数。由于这个场景是两个对象,它是基础还是&#34;助手&#34;我引用的对象(var self = this)如果是这样,我如何到达基础对象属性,例如&#34; nickNam&#34;在obj.helpers.getNickName()中?

提前致谢。

0 个答案:

没有答案