當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript object.extend函數代碼示例

本文整理匯總了TypeScript中@glimmer/object.extend函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript extend函數的具體用法?TypeScript extend怎麽用?TypeScript extend使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了extend函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: reopen

QUnit.test('using reopen() and calling _super where there is not a super function does not cause infinite recursion', assert => {
  let Taco = EmberObject.extend({
    createBreakfast(this: any) {
      // There is no original createBreakfast function.
      // Calling the wrapped _super function here
      // used to end in an infinite call loop
      this._super.apply(this, arguments);
      return 'Breakfast!';
    }
  });

  Taco.reopen({
    createBreakfast(this: any) {
      return this._super.apply(this, arguments);
    }
  });

  let taco: any = Taco.create();

  let result;
  try {
    result = taco.createBreakfast();
  } catch(e) {
    result = 'Your breakfast was interrupted by an infinite stack error.';
    throw e;
  }

  assert.equal(result, 'Breakfast!');
});
開發者ID:jayphelps,項目名稱:glimmer,代碼行數:29,代碼來源:ember-metal-mixin-reopen-test.ts

示例2: AnotherClass

QUnit.test('Sub-subclass', assert => {
  let SomeClass = EmberObject.extend({ foo: 'BAR' });
  let AnotherClass = SomeClass.extend({ bar: 'FOO' });
  let obj: any = new AnotherClass();
  assert.equal(obj.foo, 'BAR');
  assert.equal(obj.bar, 'FOO');
});
開發者ID:jayphelps,項目名稱:glimmer,代碼行數:7,代碼來源:ember-extend-test.ts

示例3: foo

QUnit.test('adds new properties to subclass', assert => {
  let Subclass: any = EmberObject.extend();
  Subclass.reopenClass({
    foo() { return 'FOO'; },
    bar: 'BAR'
  });

  assert.equal(Subclass.foo(), 'FOO', 'Adds method');
  assert.equal(get(Subclass, 'bar'), 'BAR', 'Adds property');
});
開發者ID:jayphelps,項目名稱:glimmer,代碼行數:10,代碼來源:ember-reopen-class-test.ts

示例4: foo

QUnit.test('adds new properties to subclass instance', assert => {
  let Subclass = EmberObject.extend();
  Subclass.reopen({
    foo() { return 'FOO'; },
    bar: 'BAR'
  });

  assert.equal(new Subclass()['foo'](), 'FOO', 'Adds method');
  assert.equal(get(new Subclass(), 'bar'), 'BAR', 'Adds property');
});
開發者ID:asakusuma,項目名稱:glimmer,代碼行數:10,代碼來源:ember-reopen-test.ts

示例5: SomeClass

QUnit.test('With concatenatedProperties', assert => {
  let SomeClass = EmberObject.extend({ things: 'foo', concatenatedProperties: ['things'] });
  let AnotherClass = SomeClass.extend({ things: 'bar' });
  let YetAnotherClass = SomeClass.extend({ things: 'baz' });
  let some = new SomeClass();
  let another = new AnotherClass();
  let yetAnother = new YetAnotherClass();
  assert.deepEqual(some.get('things'), ['foo'], 'base class should have just its value');
  assert.deepEqual(another.get('things'), ['foo', 'bar'], 'subclass should have base class\' and its own');
  assert.deepEqual(yetAnother.get('things'), ['foo', 'baz'], 'subclass should have base class\' and its own');
});
開發者ID:jayphelps,項目名稱:glimmer,代碼行數:11,代碼來源:ember-extend-test.ts

示例6:

QUnit.test('allows reopening already instantiated classes', assert => {
  let Subclass = EmberObject.extend();

  Subclass.create();

  Subclass.reopen({
    trololol: true
  });

  assert.equal(Subclass.create().get('trololol'), true, 'reopen works');
});
開發者ID:asakusuma,項目名稱:glimmer,代碼行數:11,代碼來源:ember-reopen-test.ts

示例7: foo

QUnit.test('Overriding a method several layers deep', assert => {
  let SomeClass = EmberObject.extend({
    fooCnt: 0,
    foo() { this.fooCnt++; },

    barCnt: 0,
    bar() { this.barCnt++; }
  });

  let AnotherClass = SomeClass.extend({
    barCnt: 0,
    bar(this: any) {
      this.barCnt++;
      this._super.apply(this, arguments);
    }
  });

  let FinalClass = AnotherClass.extend({
    fooCnt: 0,
    foo(this: any) {
      this.fooCnt++;
      this._super.apply(this, arguments);
    }
  });

  let obj: any = new FinalClass();
  obj.foo();
  obj.bar();
  assert.equal(obj.fooCnt, 2, 'should invoke both');
  assert.equal(obj.barCnt, 2, 'should invoke both');

  // Try overriding on create also
  obj = FinalClass.extend({
    foo(this: any) {
      this.fooCnt++;
      this._super.apply(this, arguments);
    }
  }).create();

  obj.foo();
  obj.bar();
  assert.equal(obj.fooCnt, 3, 'should invoke final as well');
  assert.equal(obj.barCnt, 2, 'should invoke both');
});
開發者ID:jayphelps,項目名稱:glimmer,代碼行數:44,代碼來源:ember-extend-test.ts

示例8:

QUnit.test('mergedProperties should exist even if not explicitly set on create', assert => {
  let AnObj = EmberObject.extend({
    mergedProperties: ['options'],
    options: {
      a: 'a',
      b: {
        c: 'ccc'
      }
    }
  });

  let obj = AnObj.create({
    options: {
      a: 'A'
    }
  });

  assert.equal(get(obj, 'options').a, 'A');
  assert.equal(get(obj, 'options').b.c, 'ccc');
});
開發者ID:jayphelps,項目名稱:glimmer,代碼行數:20,代碼來源:ember-metal-merged-properties-test.ts


注:本文中的@glimmer/object.extend函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。