diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..354e821 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +lesson1 \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..d821048 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/lesson1.iml b/.idea/lesson1.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/lesson1.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8662aa9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..bf48b8e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..6564d52 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..1fd8d6b --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,312 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1442782150987 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..da1ba7f --- /dev/null +++ b/index.html @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/lesson_1.js b/lesson_1.js new file mode 100644 index 0000000..60a8d4b --- /dev/null +++ b/lesson_1.js @@ -0,0 +1,37 @@ +/** + * Created by vitaliy on 21.09.15. + * Обьекты + */ + +var person = { + name:"Vitaliy", + age: 25, + gender: "male", + sayHi: function(){ + return "Hello!!"; + } +}; + +console.log(person.name); +console.log(person['age']); + +person.age = 44; +person.id = 1; + +console.log(person.id); +console.log(person.sayHi()); + +var object = Object.create({x:5, y:9});//наследуем x y +console.log(object); + +console.log(object.hasOwnProperty("x")); + +object.x = 20; +console.log(object); +console.log(object.hasOwnProperty("x")); + +//delete + +delete object.x; +console.log(object); +console.log("x" in object); \ No newline at end of file diff --git a/lesson_2.js b/lesson_2.js new file mode 100644 index 0000000..031e073 --- /dev/null +++ b/lesson_2.js @@ -0,0 +1,41 @@ +/** + * Created by vitaliy on 21.09.15. + * this и непрямой вызов методов + */ + +//var person = { +// name:"Vitaliy", +// age: 25, +// gender: "male", +// sayHi: function(){ +// return "Hello!! My name is "+this.name; +// } +//}; +// +//console.log(person.sayHi()); + +var sayHi = function(greet){ + return greet+ "Hello!! My name is "+this.name; +}; + +var person = { + name:"Vitaliy", + age: 25, + gender: "male", + sayHi: sayHi +}; + +var anotherPerson = { + name:"Dima", + age: 25, + gender: "male", + sayHi: sayHi +}; + +console.log(person.sayHi("Hi")); +console.log(anotherPerson.sayHi("Hi")); +console.log(sayHi.call(person,"Hi")); + + +var bound = sayHi.bind(person); +console.log(bound("Hello there!")); \ No newline at end of file diff --git a/lesson_3.js b/lesson_3.js new file mode 100644 index 0000000..8b59ea8 --- /dev/null +++ b/lesson_3.js @@ -0,0 +1,42 @@ +/** + * Created by vitaliy on 21.09.15. + * Аксессоры и атрибуты свойств + * ES5 + */ + +var person = { + name:"Vitaliy", + _age:20, + get age(){ + return this._age; + }, + set age (value){ + this._age = value<0 ? 0 : value > 130 ? 130 : value; + } +}; +console.log(person.age); +person.age = 150; +console.log(person.age); + +console.log(Object.getOwnPropertyDescriptor(person, "name")); +console.log(Object.getOwnPropertyDescriptor(person, "age")); + +Object.defineProperty(person,"gender",{ + value: "male", + writable: false, + enumerable: false, + configurable: false + +}); +console.log(Object.getOwnPropertyDescriptor(person, "gender")); +console.log(person); + +person.gender = "female"; + +console.log(person.gender); + +for(property in person){ + console.log(property); +} + +console.log(Object.keys(person)); \ No newline at end of file diff --git a/lesson_4.js b/lesson_4.js new file mode 100644 index 0000000..e32b199 --- /dev/null +++ b/lesson_4.js @@ -0,0 +1,33 @@ +/** + * Created by vitaliy on 21.09.15. + * Прототипы и наследование + */ + +var Person = { + constructor: function(name, age, gender){ + this.name =name; + this.age = age; + this.gender = gender; + return this; + }, + sayHi: function(){ + return "Hello!!"; + } +}; +var object = Object.create(Person).constructor('Vitaliy', 25,'male'); +console.log(object); + +console.log(Person.isPrototypeOf(object)); + +var WebDeveloper = Object.create(Person); +WebDeveloper.constructor = function(name, age, gender, skills){ + Person.constructor.apply(this, arguments); + this.skills = skills|| []; + return this; +}; +WebDeveloper.develop = function(){ + return "Working..."; +}; +var developer = Object.create(WebDeveloper).constructor("Vasa", 44, "male", ["php", "js","css"]); +console.log(developer); +console.log(developer.develop()); \ No newline at end of file diff --git a/lesson_5.js b/lesson_5.js new file mode 100644 index 0000000..2b6ed4a --- /dev/null +++ b/lesson_5.js @@ -0,0 +1,41 @@ +/** + * Created by vitaliy on 21.09.15. + * Конструкторы и классы + */ +var Person = function(name){ + this.name = name; +}; + + +Person.prototype.greet = function(){ + return "Hello, my name is " + this.name; +}; + +var person = new Person("Vitaliy"); +console.log(person); + + +console.log(person.greet()); +console.log(person.constructor); +console.log(person instanceof Person); +console.log(Person.prototype.isPrototypeOf(person)); + +console.log(Person.prototype); +console.log(person.__proto__); + + +Developer = function (name, skills){ + Person.apply(this, arguments); + this.skills = skills || []; +}; + +Developer.prototype = Object.create(Person.prototype); +console.log(Developer.prototype); +//Developer.prototype.constructor = Developer; +//console.log(Developer.prototype); + +developer = new Developer('Maria', ["ruby", "php", "mysql"]); +console.log(developer.skills); +console.log(developer.greet()); +console.log(developer instanceof Developer); +console.log(developer instanceof Person); \ No newline at end of file -- libgit2 0.21.4