本文整理匯總了TypeScript中glimmer-object.Mixin.create方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Mixin.create方法的具體用法?TypeScript Mixin.create怎麽用?TypeScript Mixin.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類glimmer-object.Mixin
的用法示例。
在下文中一共展示了Mixin.create方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
QUnit.test('Including the same mixin more than once will only run once', function() {
let cnt = 0;
let MixinA = Mixin.create({
foo() { cnt++; }
});
let MixinB = Mixin.create(MixinA, {
foo() { this._super.apply(this, arguments); }
});
let MixinC = Mixin.create(MixinA, {
foo() { this._super.apply(this, arguments); }
});
let MixinD = Mixin.create(MixinB, MixinC, MixinA, {
foo() { this._super.apply(this, arguments); }
});
let obj = {};
MixinD.apply(obj);
MixinA.apply(obj); // try to apply again..
cnt = 0;
obj['foo']();
equal(cnt, 1, 'should invoke MixinA.foo one time');
});
示例2: function
QUnit.test('mergedProperties\' overwriting methods can call _super', function() {
expect(4);
let MixinA = Mixin.create({
mergedProperties: ['foo'],
foo: {
meth(a) {
equal(a, 'WOOT', '_super successfully called MixinA\'s `foo.meth` method');
return 'WAT';
}
}
});
let MixinB = Mixin.create({
foo: {
meth(a) {
ok(true, 'MixinB\'s `foo.meth` method called');
return this._super.apply(this, arguments);
}
}
});
let MixinC = Mixin.create({
foo: {
meth(a) {
ok(true, 'MixinC\'s `foo.meth` method called');
return this._super(a);
}
}
});
let obj = mixin({}, MixinA, MixinB, MixinC);
equal(obj.foo.meth('WOOT'), 'WAT');
});
示例3: function
QUnit.test('detect() finds nested mixins', function() {
let MixinA = Mixin.create({});
let MixinB = Mixin.create(MixinA);
let obj = {};
equal(MixinA.detect(obj), false, 'MixinA.detect(obj) before apply()');
MixinB.apply(obj);
equal(MixinA.detect(obj), true, 'MixinA.detect(obj) after apply()');
});
示例4: function
QUnit.test('defining concatenated properties should concat future version', function() {
let MixinA = Mixin.create({
concatenatedProperties: null
});
let MixinB = Mixin.create({
concatenatedProperties: null
});
let obj = mixin({}, MixinA, MixinB);
deepEqual(obj.concatenatedProperties, []);
});