本文整理匯總了TypeScript中ember.Object類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Object類的具體用法?TypeScript Object怎麽用?TypeScript Object使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Object類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: testObserver
function testObserver() {
Ember.Object.extend({
valueObserver: Ember.observer('value', function() {
// Executes whenever the "value" property changes
})
});
}
示例2: testOn
function testOn() {
let Job = Ember.Object.extend({
logCompleted: Ember.on('completed', function() {
console.log('Job completed!');
})
});
let job = Job.create();
Ember.sendEvent(job, 'completed'); // Logs 'Job completed!'
}
示例3: String
(() => {
/** typeOf */
Ember.typeOf(); // $ExpectType "undefined"
Ember.typeOf(null); // $ExpectType "null"
Ember.typeOf(undefined); // $ExpectType "undefined"
Ember.typeOf('michael'); // $ExpectType "string"
// tslint:disable-next-line:no-construct
Ember.typeOf(new String('michael')); // $ExpectType "string"
Ember.typeOf(101); // $ExpectType "number"
// tslint:disable-next-line:no-construct
Ember.typeOf(new Number(101)); // $ExpectType "number"
Ember.typeOf(true); // $ExpectType "boolean"
// tslint:disable-next-line:no-construct
Ember.typeOf(new Boolean(true)); // $ExpectType "boolean"
Ember.typeOf(() => 4); // $ExpectType "function"
Ember.typeOf([1, 2, 90]); // $ExpectType "array"
Ember.typeOf(/abc/); // $ExpectType "regexp"
Ember.typeOf(new Date()); // $ExpectType "date"
Ember.typeOf(({} as any) as FileList); // $ExpectType "filelist"
Ember.typeOf(Ember.Object.extend()); // $ExpectType "class"
Ember.typeOf(Ember.Object.create()); // $ExpectType "instance"
Ember.typeOf(new Error('teamocil')); // $ExpectType "error"
Ember.typeOf((new Date()) as RegExp | Date); // "regexp" | "date"
})();
示例4: testEvented
function testEvented() {
let Person = Ember.Object.extend(Ember.Evented, {
greet() {
this.trigger('greet');
}
});
let person = Person.create();
person.on('greet', function() {
console.log('Our person has greeted');
});
person.on('greet', function() {
console.log('Our person has greeted');
}).one('greet', function() {
console.log('Offer one-time special');
}).off('event', {}, function() {});
person.greet();
}
示例5: createMan
import Ember from 'ember';
let App: any;
App = Ember.Application.create();
App.president = Ember.Object.create({
name: 'Barack Obama',
});
App.country = Ember.Object.create({
presidentNameBinding: 'MyApp.president.name',
});
App.country.get('presidentName');
App.president = Ember.Object.create({
firstName: 'Barack',
lastName: 'Obama',
fullName: Ember.computed(function() {
return `${this.get('firstName')} ${this.get('lastName')}`;
}),
});
App.president.get('fullName');
declare class MyPerson extends Ember.Object {
static createMan(): MyPerson;
}
MyPerson.createMan();
const Person1 = Ember.Object.extend({
say: (thing: string) => {
alert(thing);
},
});
示例6:
import Ember from 'ember';
import { assertType } from './lib/assert';
const ExtendClass = Ember.Object.extend({
foo: 'hello'
});
class ES6Class extends Ember.Object {
bar: string;
}
let TestClass = Ember.Object;
if (ExtendClass.detect(TestClass)) {
assertType<string>(TestClass.create().foo);
}
if (ES6Class.detect(TestClass)) {
assertType<string>(TestClass.create().bar);
}
示例7: function
const Person = Ember.Object.extend({
firstName: '',
lastName: '',
age: 0,
noArgs: Ember.computed<string>(() => 'test'),
fullName: Ember.computed<string>('firstName', 'lastName', function() {
return `${this.get('firstName')} ${this.get('lastName')}`;
}),
fullNameReadonly: Ember.computed<string>('fullName', function() {
return this.get('fullName');
}).readOnly(),
fullNameWritable: Ember.computed<string>('firstName', 'lastName', {
get() {
return this.get('fullName');
},
set(key, value) {
const [first, last] = value.split(' ');
this.set('firstName', first);
this.set('lastName', last);
return value;
}
}),
fullNameGetOnly: Ember.computed<string>('fullName', {
get() {
return this.get('fullName');
}
}),
fullNameSetOnly: Ember.computed<string>('firstName', 'lastName', {
set(key, value) {
const [first, last] = value.split(' ');
this.set('firstName', first);
this.set('lastName', last);
return value;
}
}),
combinators: Ember.computed<string>(function() {
return this.get('firstName');
}).property('firstName')
.meta({ foo: 'bar' })
.volatile()
.readOnly(),
explicitlyDeclared: alias('fullName') as Computed<string>,
});
示例8:
this.edit();
}
}
});
const comment = EditableComment.create({
postId: 42
});
comment.edit();
comment.canEdit();
comment.tryEdit();
assertType<boolean>(comment.isEditing);
assertType<number>(comment.postId);
const LiteralMixins = Ember.Object.extend({ a: 1 }, { b: 2 }, { c: 3 });
const obj = LiteralMixins.create();
assertType<number>(obj.a);
assertType<number>(obj.b);
assertType<number>(obj.c);
/* Test composition of mixins */
const EditableAndCancelableMixin = Ember.Mixin.create(EditableMixin, {
cancelled: false,
});
const EditableAndCancelableComment = Ember.Route.extend(EditableAndCancelableMixin);
const editableAndCancelable = EditableAndCancelableComment.create();
assertType<boolean>(editableAndCancelable.isEditing);
assertType<boolean>(editableAndCancelable.cancelled);
示例9:
import Ember from 'ember';
import { assertType } from './lib/assert';
type Person = typeof Person.prototype;
const Person = Ember.Object.extend({
name: '',
isHappy: false
});
const people = Ember.A([
Person.create({ name: 'Yehuda', isHappy: true }),
Person.create({ name: 'Majd', isHappy: false }),
]);
assertType<number>(people.get('length'));
assertType<Person>(people.get('lastObject'));
assertType<boolean>(people.isAny('isHappy'));
assertType<boolean>(people.isAny('isHappy', 'false'));
assertType<Ember.Enumerable<Person>>(people.filterBy('isHappy'));
assertType<Ember.Enumerable<Person>>(people.rejectBy('isHappy'));
assertType<Ember.Enumerable<Person>>(people.filter((person) => person.get('name') === 'Yehuda'));
assertType<typeof people>(people.get('[]'));
assertType<Person>(people.get('[]').get('firstObject'));
assertType<Ember.Array<boolean>>(people.mapBy('isHappy'));
assertType<any[]>(people.mapBy('name.length'));
const last = people.get('lastObject');
if (last) {
assertType<string>(last.get('name'));
}
示例10: init
import Ember from 'ember';
const LifetimeHooks = Ember.Object.extend({
resource: null as {} | null,
init() {
this._super();
this.resource = {};
},
willDestroy() {
delete this.resource;
this._super();
}
});