Authored by yyq

es6 test

... ... @@ -4,6 +4,9 @@
* @date: 2015/11/23
*/
import {timeout} from './es6-test';
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload');
... ... @@ -13,6 +16,19 @@ var homePage = $('.home-page').data('page'),
var yas = require('../common/data-yas');
const defTimeout = (time, type = 'default') => {
return timeout(time).then(()=> {
console.log(`${type} timeout`);
});
};
(async function() {
await defTimeout(10000, 'await');
defTimeout(500);
console.log('async end');
}());
// 给头部js获取当前频道
window.homePage = homePage;
... ...
class Animal {
constructor() {
this.type = 'animal';
}
says(say = 'hi') {
setTimeout(() => {
console.log(`${this.type} says ${say}`);
}, 1000);
}
}
class Cat extends Animal {
constructor() {
super();
this.type = 'cat';
}
setInfo(info) {
let {name, age, color} = info;
name && (this.name = name);
age && (this.age = age);
color && (this.color = color);
}
infos() {
console.log(this);
}
}
const timeout = (ms) => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
};
function* generator() {
yield 'hello';
yield 'generator';
}
let cat = new Cat();
cat.says();
cat.setInfo({name: 'mini', color: 'black'});
cat.infos();
console.log([...generator()]);
export {
cat,
timeout
};
... ...