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 myPromiseFactory() { | |
| return somethingThatCreatesAPromise(); | |
| } | |
| function executeSequentially(promiseFactories) { | |
| var result = Promise.resolve(); | |
| promiseFactories.forEach(function (promiseFactory) { | |
| result = result.then(promiseFactory); // promiseFactory is executed and return Promise for next then() | |
| }); |
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
| // userdata.js | |
| class User { | |
| constructor(name) { | |
| this.name = name; | |
| } | |
| } | |
| export class Item { | |
| constructor(name) { |
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
| // Fail var | |
| for (var i = 1; i <= 3; i++) { | |
| console.log('forloop', i) | |
| Promise.resolve().then(() => { | |
| console.log(i); // Always log 5 | |
| }) | |
| } | |
| // Use let instead | |
| for (let i = 1; i <= 3; i++) { |
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
| var a = new Promise((resolve,reject)=>{ | |
| // Do someting | |
| resolve('data'); | |
| }) | |
| .then((data)=>{ | |
| console.log(data) | |
| // Do something | |
| // Delay 5000ms | |
| return new Promise((resolve,reject)=>{ | |
| setTimeout(()=>{ |
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
| // Catch function before then function | |
| var a = Promise.reject('ErrorValue') | |
| .catch((err) => { | |
| console.log('Catch', 'PromiseValue', err) | |
| }) | |
| .then((data) => { | |
| console.log('Then', 'PromiseValue', 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
| <html> | |
| <body> | |
| <ul id="item-list"> | |
| <li>Item1</li> | |
| <li>Item2</li> | |
| <li>Item3</li> | |
| <li>Item4</li> | |
| <li>Item5</li> | |
| </ul> |
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
| <html lang="en"> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html;charset:utf-8"> | |
| <title>Event Delegate</title> | |
| </head> | |
| <body> | |
| <ul> | |
| <li><a href="#">item 1</a></li> | |
| <li><a href="#">item 2</a></li> | |
| <li><a href="#">item 3</a></li> |
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
| public class StaticProperty { | |
| public static class Person { | |
| static int staticProperty = 10; | |
| String name; | |
| public Person(String name) { | |
| this.name = name; | |
| } |
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 Person(): | |
| static_property = 10 | |
| def __init__(self, name): | |
| self.name = name | |
| john = Person('john') | |
| print(john.static_property) # 10 => find in prototype | |
| john.static_property = 5 # Create new own property |
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 Person(name) { | |
| this.name = name; | |
| } | |
| Person.prototype.staticProperty = 10; | |
| var john = new Person('john'); | |
| console.log(john.staticProperty); // 10 | |
| john.staticProperty = 5; | |
| console.log(Person.staticProperty) // 10 |