This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const myObject = { | |
| a: 'b', | |
| b: 'c', | |
| doStuff: function() { | |
| // Here, this refers to myObject | |
| console.log(this.a + this.b); | |
| } | |
| } | |
| myObject.doStuff(); // bc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Here, '5' will be converted to 5 */ | |
| 5 == '5'; // true | |
| 5 === '5'; // false | |
| /* Here, true will be converted to 1 */ | |
| 1 == true; // true | |
| 1 > false; // true | |
| 0 === false; // false | |
| // Here, JS will try to convert both of these to number |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function doStuff() { | |
| // both a and b will be available for this function, but not outside | |
| let a = 5; | |
| var b = 5; | |
| console.log(a + b); // 10 | |
| } | |
| doStuff(); // 10; | |
| console.log(a); // ReferenceError |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // HACK: Since TypeScript inherits static properties too, we have to | |
| // fight against TypeScript here so Subject can have a different static create signature | |
| /** | |
| * Creates a new cold Observable by calling the Observable constructor | |
| * @static true | |
| * @owner Observable | |
| * @method create | |
| * @param {Function} subscribe? the subscriber function to be passed to the Observable constructor | |
| * @return {Observable} a new cold observable | |
| * @nocollapse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // TODO: do this more elegantly | |
| ;((currentReducer as unknown) as Reducer< | |
| NewState, | |
| NewActions | |
| >) = nextReducer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const stringValidatorHandler = { | |
| set: (obj, key, value) => { | |
| if (typeof value !== 'string') { | |
| throw new Error('Expected string!') | |
| } | |
| obj[key] = value.toUpperCase(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const defaultValueHandler = { | |
| get: (obj, property) => | |
| property in obj ? obj[property] : 'general kenobi' | |
| } | |
| const objectWithDefaultValue = new Proxy({}, defaultValueHandler); | |
| objectWithDefaultValue.a = 'b'; | |
| console.log(objectWithDefaultValue.a); // b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const client = ClientBuilder() | |
| .forBaseUrl('https://some-api.com/api/') | |
| .withHeaders({Authorization: 'Bearer ABACABA'}) | |
| .usingAxios() | |
| .build(); | |
| client.post('UpdateData', {data: 'new data'}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function executeWithFetch(request) { | |
| // EXERCISE FOR THE READER | |
| } | |
| function executeWithAxios(request) { | |
| // EXERCISE FOR THE READER | |
| } | |
| function ClientBuilder() { | |
| return { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Main { | |
| public static void main(String[] args) { | |
| StringBuilder sb = new StringBuilder(); | |
| String info = | |
| sb.append("Version: ") | |
| .append(VersionSignleton.getVersion()) | |
| .append(" running on: ") | |
| .append(System.getProperty("os.arch")) | |
| .toString(); | |