Различия
Показаны различия между двумя версиями страницы.
| java-script:docs:context [2018/04/28 01:38] – создано mirocow | java-script:docs:context [2018/04/28 01:38] (текущий) – [Контекст] mirocow | ||
|---|---|---|---|
| Строка 1: | Строка 1: | ||
| ====== Контекст ====== | ====== Контекст ====== | ||
| + | ==== From an instance context: ==== | ||
| + | |||
| + | <code javascript> | ||
| + | function A() { | ||
| + | this.getClass = function() { | ||
| + | return window[this.constructor.name]; | ||
| + | } | ||
| + | |||
| + | this.getNewInstance = function() { | ||
| + | return new window[this.constructor.name]; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | var a = new A(); | ||
| + | console.log(a.getClass()); | ||
| + | |||
| + | // you can even: | ||
| + | var b = new a.getClass(); | ||
| + | b instanceof A; // true | ||
| + | </ | ||
| ==== From static context: ==== | ==== From static context: ==== | ||