Skip to content

Instantly share code, notes, and snippets.

View solominh's full-sized avatar

Minh Tran solominh

View GitHub Profile
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()
});
// userdata.js
class User {
constructor(name) {
this.name = name;
}
}
export class Item {
constructor(name) {
// 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++) {
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(()=>{
// Catch function before then function
var a = Promise.reject('ErrorValue')
.catch((err) => {
console.log('Catch', 'PromiseValue', err)
})
.then((data) => {
console.log('Then', 'PromiseValue', data)
})
<html>
<body>
<ul id="item-list">
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
<li>Item5</li>
</ul>
<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>
public class StaticProperty {
public static class Person {
static int staticProperty = 10;
String name;
public Person(String name) {
this.name = name;
}
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
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