-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9bc3181
Showing
7 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const WindowsVersion = { | ||
name: 'Windows 7', | ||
version: '6.1', | ||
year: 2009, | ||
developer: 'Microsoft Corporation', | ||
}; | ||
|
||
getObjectValues(WindowsVersion); | ||
|
||
function getObjectValues(obj) { | ||
for (var key in obj) { | ||
console.log(key + ' = ' + obj[key]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const WindowsVersion = { | ||
name: 'Windows 7', | ||
version: '6.1', | ||
year: 2009, | ||
developer: 'Microsoft Corporation', | ||
}; | ||
|
||
console.log(isProperty(WindowsVersion, 'developer')); | ||
|
||
function isProperty(object, property) { | ||
if (object.hasOwnProperty(property)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const myObj = newObject(); | ||
|
||
function newObject() { | ||
return new Object(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function ElectricalAppliance(name, power) { | ||
this.name = name; | ||
this.power = power; | ||
this.isPlugged = false; | ||
} // метод, который определяет прибор как включенный в розетку | ||
|
||
ElectricalAppliance.prototype.plugIn = function() { | ||
console.log(this.name + " is plugged!"); | ||
this.isPlugged = true; | ||
} | ||
|
||
ElectricalAppliance.prototype.getPowerUsed = function() { | ||
return this.isPlugged ? this.power : 0; | ||
} | ||
|
||
const lampa = new ElectricalAppliance('lampa', 45); | ||
const tv = new ElectricalAppliance('tv', 1000); | ||
|
||
console.log(lampa.getPowerUsed() + tv.getPowerUsed()); | ||
|
||
lampa.plugIn(); | ||
console.log(lampa.getPowerUsed() + tv.getPowerUsed()); | ||
|
||
tv.plugIn(); | ||
console.log(lampa.getPowerUsed() + tv.getPowerUsed()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class ElectricalAppliance | ||
{ | ||
constructor(name, power) | ||
{ | ||
this.name = name; | ||
this.power = power; | ||
this.isPlugged = false; | ||
} | ||
|
||
plugIn() | ||
{ | ||
console.log(this.name + " is plugged!"); | ||
this.isPlugged = true; | ||
} | ||
|
||
getPowerUsed() | ||
{ | ||
return this.isPlugged ? this.power : 0; | ||
} | ||
} | ||
|
||
const lampa = new ElectricalAppliance('lampa', 45); | ||
const tv = new ElectricalAppliance('tv', 1000); | ||
|
||
console.log(lampa.getPowerUsed() + tv.getPowerUsed()); | ||
|
||
lampa.plugIn(); | ||
console.log(lampa.getPowerUsed() + tv.getPowerUsed()); | ||
|
||
tv.plugIn(); | ||
console.log(lampa.getPowerUsed() + tv.getPowerUsed()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Задание 1. | ||
Написать, функцию, которая принимает в качестве аргумента объект и выводит в консоль все ключи и значения только собственных свойств. Данная функция не должна возвращать значение. | ||
|
||
Задание 2. | ||
Написать функцию, которая принимает в качестве аргументов строку и объект, а затем проверяет есть ли у переданного объекта свойство с данным именем. Функция должна возвращать true или false. | ||
|
||
Задание 3. | ||
Написать функцию, которая создает пустой объект, но без прототипа. | ||
|
||
Задание 4. | ||
Реализуйте следующее консольное приложение подобно примеру, который разбирался в видео. Реализуйте его на прототипах. | ||
Определите иерархию электроприборов. Включите некоторые в розетку. Посчитайте суммарную потребляемую мощность всех включенных приборов (передайте аргумент). | ||
Таких приборов должно быть как минимум два (например, настольная лампа и компьютер). Выбрав прибор, подумайте, какими свойствами он обладает. | ||
|
||
Задание 5. | ||
Переписать консольное приложение из предыдущего юнита на классы. |