Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

java-script:docs:context [2018/04/28 01:38] – создано mirocowjava-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());  //  function A { // etc... }
 +
 +// you can even:
 +var b = new a.getClass();
 +b instanceof A; // true
 +</code>
 ==== From static context: ==== ==== From static context: ====