看不懂一段别人的代码,跪求大佬讲解
发布于 5 年前 作者 yong62 451 次浏览 来自 问答

var datas = {

limit: 10,

offset: offset,

}

console.log(datas)

if (that.data.gameType != ‘’) {

datas

.

gameType = that.data.gameType;

}

if (that.data.ballType != ‘’) {

datas.ballType = that.data.ballType;

}

这段代码定义了一个对象datas,但是后面为什么可以添加gameType 和ballType 两个字段?求解释。代码不存在问题

6 回复

这些代码上边还有一个 var that = this;你没复制过来吧,你说that.data这个操作的是js文件的page里定义的data

给你推荐几本书吧,JavaScript高级程序设计,JavaScript面向对象编程指南,JavaScript权威指南。基础要扎实呀

JS的对象很灵活,想加属性加属性,想加方法加方法,反之亦然。

兄弟,好好读书,天天向上

var a = { test: ‘test’ };

等价于

var a = {};  a.test = ‘test’;

回到顶部