Rxjs: Alias of -> just ?

Created on 26 Oct 2017  路  5Comments  路  Source: ReactiveX/rxjs

RxJS version:
5.5.2
Code to reproduce:

like renamed operators in rxjs/operators

Most helpful comment

Wow this is an amusing one. While of is _not_ a keyword it is a built in, for use in for of loops. You can do some silly things with the fact that of can be assigned. It doesn't change the semantics of a for(x of ...) though.

> var of = "yep"
undefined
> for(y of [1,2,3]) { console.log(y) }
1
2
3
undefined
> of
'yep'

since of is a valid variable name:

> of = [1,2,3]
[ 1, 2, 3 ]
> for(of of of) { console.log(of) }
1
2
3

All 5 comments

Mind share bit more details?

ha, of is a reserved word in JavaScript

In my Angular app I could have code looking like this

import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { Observable } from 'rxjs/Observable';

or this

import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { of } from 'rxjs/observable/of';
import { catchError, share, tap } from 'rxjs/operators';
import { Observable } from 'rxjs/Observable';

Editor colorization for of as a function treats it like the of keyword in js. In my color theme in VSCode, of is blue like this and true whereas my other functions are yellow. Slightly confusing and can be dealt with as @Brooooooklyn said by using an alias like with tap and catchError.

Wow this is an amusing one. While of is _not_ a keyword it is a built in, for use in for of loops. You can do some silly things with the fact that of can be assigned. It doesn't change the semantics of a for(x of ...) though.

> var of = "yep"
undefined
> for(y of [1,2,3]) { console.log(y) }
1
2
3
undefined
> of
'yep'

since of is a valid variable name:

> of = [1,2,3]
[ 1, 2, 3 ]
> for(of of of) { console.log(of) }
1
2
3

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peterbakonyi05 picture peterbakonyi05  路  4Comments

OliverJAsh picture OliverJAsh  路  3Comments

benlesh picture benlesh  路  3Comments

Agraphie picture Agraphie  路  3Comments

shenlin192 picture shenlin192  路  3Comments