下面是apply和call功能:
function.apply(context, [args])
function.call(context, arg1, arg2, ...)
我们知道和之间的区别:applycall
不同之处在于 apply 允许您使用数组形式的参数来调用函数;调用需要显式列出参数。
现在我们有了扩展语法,我们可以轻松地使用它call来执行以下apply操作:
function.call(context, ...[args])
那么对于展开语法,我们什么时候使用applyover呢call?我很好奇apply功能是否可以退休。
我有一个 CloudFormation 模板,它的Outputs部分是这样的:
"Outputs": {
"QueueSubscriptions": {
"Description": "Topics subscribed by queue",
"Value": {
"Fn::GetAtt" : [ "BRIDGE2ESBQUEUE", "Subscriptions" ]
}
}
}
Run Code Online (Sandbox Code Playgroud)
是Subscriptions一个数组。所以,我得到了错误Template format error: Every Value member must be a string。有没有办法输出Subscriptions模板中的数组?谢谢。
我正在使用数据库服务中的数据实现自动完成:
@Injectable()
export class SchoolService {
constructor(private db: AngularFirestore) {
}
getSchools(): Observable<School[]> {
return this.db.collection<School>('schools').valueChanges();
}
}
Run Code Online (Sandbox Code Playgroud)
在我的组件中:
export class SchoolComponent implements OnInit {
formControl: FormControl = new FormControl();
schools: Observable<School[]>;
filteredSchools: Observable<School[]>;
constructor(private schoolService: SchoolService) {
}
ngOnInit() {
this.schools = this.schoolService.getSchools();
//Below line gives error "Type Observable<Observable<School[]>> is not assignable to type Observable<School[]>".
this.filteredSchools = this.formControl.valueChanges.pipe(
startWith(''),
map(name => this.filterSchools(name))
);
}
filterSchools(name: string): Observable<School[]> {
return this.schools.map(school => school.filter(s => s.name.toLowerCase().includes(name)));
}
}
Run Code Online (Sandbox Code Playgroud)
和我的HTML:
<form>
<mat-form-field> …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的SpringApplicationRunListener实现。
public class AppListener implements SpringApplicationRunListener {
private long appStartTimestamp;
private long appFinishTimestamp;
public AppListener(SpringApplication application, String[] args) {
}
@Override
public void started() {
appStartTimestamp = System.currentTimeMillis();
}
@Override
public void environmentPrepared(ConfigurableEnvironment environment) {
//Not used.
}
@Override
public void contextPrepared(ConfigurableApplicationContext context) {
//Not used.
}
@Override
public void contextLoaded(ConfigurableApplicationContext context) {
//Not used.
}
@Override
public void finished(ConfigurableApplicationContext context, Throwable exception) {
appFinishTimestamp = System.currentTimeMillis();
}
public long getAppStartTimestamp() {
return appStartTimestamp;
}
public long getAppFinishTimestamp() …Run Code Online (Sandbox Code Playgroud) angular ×1
ecmascript-6 ×1
javascript ×1
rxjs ×1
rxjs5 ×1
spring ×1
spring-boot ×1
typescript ×1