gpt4 book ai didi

javascript - 在设置同一对象的其他属性时将属性作为参数传递

转载 作者:行者123 更新时间:2023-11-29 21:47:44 27 4
gpt4 key购买 nike

我正在使用 Raphael.js 制作一个 JS 小游戏。这是我在 JS 中的第一个大项目,所以我不熟悉所有的设计模式等。我正在尝试制作一个代表移动计时器的对象。从“litCircle”行开始,出现错误:

Uncaught TypeError: Cannot read property '0' of undefined

c 是我的拉斐尔对象。有什么我不知道的地方,你不能在你用来帮助设置对象其他属性值的函数调用中使用你当前定义的对象的属性吗?

var moveTimer = {
mtScaler : 15,
all : c.set(),
RS : [1*this.mtScaler,3*this.mtScaler,4*this.mtScaler],
litCircle : c.circle(200,37,this.RS[0]),
midCircle : c.circle(200,37,this.RS[1]).attr({
"stroke-dasharray": "- "
}),
bigCircle : c.circle(200,37,this.RS[2]).attr({
"stroke-dasharray":". "}),
orangeOne : c.circle(200, 37,this.RS[0]).attr({
"stroke-width": 2,
"stroke": COLOR_DICT["orange"],
}),
turnCounter : c.text(200,38,0),
orangeAnim :
Raphael.animation({
"50%": { r: this.RS[2] },
"100%": { r: this.RS[0] }
}, 3000),
finish : function(){
this.all.push(this.litCircle, this.midCircle, this.bigCircle,
this.orangeOne, this.turnCounter);
this.all.transform("t250,230");
}
}

最佳答案

RS 在您调用它时仍在定义中,定义一些定义之外的变量并使用它们。

例子:

var scaler, rs;
scaler = 15;
rs = [1*tscaler,3*tscaler,4*scaler];

var moveTimer = {
mtScaler : scaler,
all : c.set(),
RS : rs,
litCircle : c.circle(200,37,rs[0]),
midCircle : c.circle(200,37,rs[1]).attr({
"stroke-dasharray": "- "
}),
bigCircle : c.circle(200,37,this.RS[2]).attr({
"stroke-dasharray":". "}),
orangeOne : c.circle(200, 37,this.RS[0]).attr({
"stroke-width": 2,
"stroke": COLOR_DICT["orange"],
}),
turnCounter : c.text(200,38,0),
orangeAnim :
Raphael.animation({
"50%": { r: this.RS[2] },
"100%": { r: this.RS[0] }
}, 3000),
finish : function(){
this.all.push(this.litCircle, this.midCircle, this.bigCircle,
this.orangeOne, this.turnCounter);
this.all.transform("t250,230");
}
}

This may not be 100% since I can't confirm the code, but is a starting place.

关于javascript - 在设置同一对象的其他属性时将属性作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30520297/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com