我想知道如何在匿名函数中访问和修改变量a,我尝试放箭头,但是我进入浏览器:未定义
import * as Konva from 'konva';
export class classTest {
public a: number;
access(){
var stage = new Konva.Stage({ container: 'container', width: 400, height: 250 });
var layer1 = new Konva.Layer();
var imageObj = new Image();
var self = this
imageObj.onload = function () {
self.a = 150
var yoda = new Konva.Image({
x: 50,
y: 50,
image: imageObj,
width: 106,
height: 118
});
layer1.add(yoda);
//stage.add(layer1)
};
imageObj.src = '/assets/images/yoda.jpg';
//console.log(a)
如果我在layer1中添加一个width = a的矩形,它将与您解释的相同(我得到一条线),那么我该怎么做。
var box = new Konva.Rect({
x: 20, y: 20,
width: this.a,
height: 50,
fill: '#00D2FF', stroke: 'black',
strokeWidth: 4
});
stage.add(layer1)
}
答案 0 :(得分:0)
SELECT *, .... AS membership FROM customer;
+-----------+----+---------+----------+
|customer_id|name|telephone|membership|
+-----------+----+---------+----------+
| 1 |Andi|+62932011| Plus |
| 2 |Boby|+62928291| Regular |
| 3 |Jane|+62932212| Regular |
| 4 |John|+62999021| Regular |
| 5 |Beth|+62999021| Regular |
| 6 |Noel|+62999021| Plus |
+-----------+----+---------+----------+
早于
执行 console.log(this.a);
这就是为什么您获得imageObj.onload
在undefined
内部,一切正常。