use*_*880 2 html javascript jquery
我正在使用以下代码创建一个Grid对象:
var Grid = {
rows: 5,
cols: 6,
getDimensions: function() {
console.log(rows + ' by ' + cols);
}(),
};
Run Code Online (Sandbox Code Playgroud)
我的getDimensions
功能不工作但因为它无法引用rows
和cols
我以前设置的属性.this
设置为窗口,所以我不知道如何引用这些属性.
var Grid = {
rows: 5,
cols: 6,
getDimensions: function() {
console.log(this.rows + ' by ' + this.cols);
}(),
};
Run Code Online (Sandbox Code Playgroud)
使用this
引用对象的其他属性.记住范围.或者你可以使用Grid.rows
和Grid.cols