index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<script src="1.js" defer></script>
</head>
<body>
</body>
</html>
1.js
var man = {
"name" : "Alex",
"age" : 67,
"id" : "22334",
"sex" : "male"
};
/*console.log(man);
console.log(man.name);
console.log(man['name']);
var a = 'name';
console.log(man[a]);*/
var man2 = {
"name" : "Alex",
"age" : 67,
"id" : "22334",
"sex" : "male",
"year" : function() {
return 2017-this.age;
}
};
console.log(man2.year());
var m = {
"mas" : [5, 6, 34, 12, 45],
"sum" : function(){
var sum = 0;
for(var i = 0; i < this.mas.length; i++) {
sum = sum + this.mas[i];
}
return sum;
}
};
console.log(m.sum());
Комментариев нет:
Отправить комментарий