Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
var Zoo = Zoo || {};if (window.Zoo) { // в общем случае someScope.object
Zoo = Zoo;
} else {
Zoo = {};
}someConditionTrue && doSomething();
if (someConditionTrue) {
doSomething();
}$array = array(); !$array && ($array = array(1, 2, 3));
= += -= *= /= .= %= &= |= ^= <<= >>=
ECMAScript is an object-oriented programming language
.python:
my_obj = {
'a': 10,
'test': lambda x: x + 10,
'b': 20
}
my_obj['a'] # 10
my_obj['test'](10) # 20
my_obj['b'] # 20dynamic class A {
function test() {}
prototype function test2() {}
}
var a = new A();
var b = new A();
print a.test === b.test; // false
print a.test2 === b.test2; // truedynamic class A {
function test1() {}
prototype function test2() {}
}
dynamic class B extends A {
function test3() {}
prototype function test4() {}
}
var a = new B();
var b = new B();
a.test1 === b.test1 // false
b.test2 === b.test2 //true
a.test3 === b.test3 // false
a.test4 === b.test4 // true
The . operator produces a function (more specifically, a closure) that is already dispatched and has this bound to the left operand of the. operator.
class A(object):
def __init__(self, a=10):
self.a = a
def test(self):
print self.a
a = A(20)
a.a # 20
del a.a
a.a # None
a.a = 10
a.test() #10
a.b = 20 #20 (собственное свойство)
b = A()
b.a #10 (по умолчанию из конструктора)
a.__class__.c = 30 # расширили класс новым свойство
a.c # 30 оно доступно (посредством делегирования) во всех порожденных инстансах
b.c # тоже 30
a.c = 40 # перезаписали, свойство "с" теперь свое
a.c # 40
b.c # 30 - делегация
del a.c
a.c # 30 снова делегация
del A # удаляем ссылку на объект-класс
b.__class__.d = 50 # но все еще можем расширять объект-класс через инстансы
a.d # 50
b.d # 50dynamic class A {
function test() {}
}
var a = new A();
var b = new B();
a.test();
b.test();
a.test === b.test // false
a.hasOwnProperty('test'); // true
b.hasOwnProperty('test'); // true
// наследование - как в Java
class B extends A {} // и т.д.function A() {
this.test = function () {};
}
// дальше тоже самое
JsOOP