Last active
August 29, 2015 14:15
-
-
Save toropanov/6ba63eb1e39484b23d9b to your computer and use it in GitHub Desktop.
Working with Objects
This file contains hidden or 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
// Create empty object | |
var mikhail = Object.create(null) | |
// Updating values | |
mikhail['name'] = 'Mikhail' | |
// or also could be like this | |
mikhail.name = 'Mikhail' | |
// Deleting property in object | |
delete mikhail['gender'] | |
// Adding to existing objects объекту | |
Object.defineProperties(array_name, { name: { value: 'Value' | |
, writable: true | |
, configurable: true | |
, enumerable: true } | |
// As a value in object could be also used function | |
var mikhail = { name: 'Mikhail' | |
, get name() { | |
return this.first_name + ' ' + this.last_name } | |
, set name(new_name) { var names | |
names = new_name.trim().split(/\s+/) | |
this.first_name = names['0'] || '' | |
this.last_name = names['1'] || '' } | |
} | |
// One more example with function in object | |
function add(other, yet_another) { | |
return this.value + other + (yet_another || 0) | |
} | |
var one = { value: 1, add: add } | |
// Creating protype | |
var mikhail = Object.create(person) |
This file contains hidden or 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
function Class(){/*тут инициализируем поля *} | |
Class.prototype = {/*Методы*/} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment