对象:

1.1生成方法

对象(object)是 JavaScript 语言的核心概念,也是最重要的数据类型。对象就是一组“键值对”(key-value)的集合,是一种无序的复合数据集合。

1.2
对象的所有键名都是字符串(ES6 又引入了 Symbol 值也可以作为键值),所以加不加引号都可以。上面的代码也可以写成下面这样。

如果键名是数值,会被自动转为字符串。
如果属性的值还是一个对象,就形成了链式引用。
对象的属性之间用逗号分隔,最后一个属性后面可以加逗号(trailing comma),也可以不加。
属性可以动态创建,不必在对象声明时就指定。

o1o2指向同一个对象,然后o1的值变为1,这时不会对o2产生影响,o2还是指向原来的那个对象。但是,这种引用只局限于对象,如果两个变量指向同一个原始类型的值。那么,变量这时都是值的拷贝。



对象采用大括号表示,这导致了一个问题:如果行首是一个大括号,它到底是表达式还是语句?
{ foo:123 }
第一种可能是,这是一个表达式,表示一个包含foo属性的对象;第二种可能是,这是一个语句,表示一个代码区块,里面有一个标签foo,指向表达式123
这种差异在eval语句(作用是对字符串求值)中反映得最明显。
eval将其理解为一个代码块;加上圆括号以后,就理解成一个对象。

var obj = { p: 1 };

// 等价于

var obj = {};
obj.p = 1;


查看一个对象本身的所有属性,可以使用Object.keys方法。
var obj = {
  key1: 1,
  key2: 2
};

Object.keys(obj);
// ['key1', 'key2']

for...in循环用来遍历一个对象的全部属性。
var obj = {a: 1, b: 2, c: 3};

for (var i in obj) {
  console.log(obj[i]);
}


某个属性是否为对象自身的属性。
var person = { name: '老张' };

for (var key in person) {
  if (person.hasOwnProperty(key)) {
    console.log(key);
  }
}
// name


with语句的格式如下:

with (对象) {
  语句;
}
// 例一
var obj = {
  p1: 1,
  p2: 2,
};
with (obj) {
  p1 = 4;
  p2 = 5;
}
// 等同于
obj.p1 = 4;
obj.p2 = 5;

// 例二
with (document.links[0]){
  console.log(href);
  console.log(title);
  console.log(style);
}
// 等同于
console.log(document.links[0].href);
console.log(document.links[0].title);
console.log(document.links[0].style);
注意,如果with区块内部有变量的赋值操作,必须是当前对象已经存在的属性,否则会创造一个当前作用域的全局变量。

每日单词学习ing
diet 饮食,日常食物
fat 脂肪
fit 健康
flu 流行性感冒
rare 稀少的,y罕有的
toothache牙痛
unhealthy 不健康的
wealthy 富裕的
rarely 稀少地
proverb 谚语
anxious 焦虑
captain 队长
injure 伤害
injury 伤害损伤
pain 疼痛
painful 疼痛的
normal 正常
lifestyle 生活方式
head 朝。。。。方向前进
eye 注视
overweight 超重
lung 肺部
throat 咽喉
breathe 呼吸
pneumonia 肺炎
symptom 症状
X-ray X光
awful 可怕的
insurance 保险
question-naire 问卷 问卷调查
be connected with 与。。。联系
take exercise 锻炼
be crazy about 迷恋
have a temperature 发烧
lie down 躺下
begin with put ... into ... 以什么开始
become ill 生病





A Canadian student has been fined Canadian $400 for looking at her Apple smartwatch while waiting at traffic lights.


一名加拿大学生因在等红绿灯时看了她的苹果智能手表,被罚款400加币。

Victoria Ambrose was found guilty of breaking Ontario's distracted driving law. In court, Ms Ambrose said she looked at the watch to find out the time.

这名名叫维多利亚·安布罗斯的学生,因分心而违反了安大略省的驾驶法规而被判有罪。在法庭上,安布罗斯表示,她只是拿出手表查看一下时间。

This claim was rejected by the judge who said smartwatches were a distraction as much as a "cellphone taped to someone's wrist".

该辩解被法官驳回,法官认为智能手表就像是“戴在手腕处的手机”,会令人分心。

Ms Ambrose got a traffic ticket in April after being seen by a police officer from the University of Guelph.

今年4月,在被盖尔夫大学的一名警察看到(等红灯时看手表)之后,安布罗斯女士获得了一张交通罚单。
 

In court, the police officer said Ms Ambrose did not move off when the light turned green because her attention was fixed on the watch. She only started moving when the officer shone a side light from the police cruiser at her car.

在法庭上,这名警察表示,安布罗斯女士因注意力在手表上,所以在绿灯的时候没有启动汽车,直到警察用巡警车灯提醒她。
The officer then pulled Ms Ambrose over and issued the ticket, reported the National Post.
据《国家邮报》报道,随后该警察让安布罗斯靠边停车并开具罚单。
The Canadian student is not the first to get a ticket for breaking the country's laws governing driver distraction by consulting a smartwatch. In 2015, a Quebec man was fined C$120 and given four points on his licence for using his Apple Watch while driving.
这名加拿大学生并不是第一个因为智能手表分心而违反加拿大交通法的人。2015年,魁北克的一名男子因在开车时使用他的苹果手表,遭到120加币的罚款和扣除4分驾照积分的处罚。