Authored by yyq

es6 test

@@ -4,6 +4,9 @@ @@ -4,6 +4,9 @@
4 * @date: 2015/11/23 4 * @date: 2015/11/23
5 */ 5 */
6 6
  7 +
  8 +import {timeout} from './es6-test';
  9 +
7 var $ = require('yoho-jquery'), 10 var $ = require('yoho-jquery'),
8 lazyLoad = require('yoho-jquery-lazyload'); 11 lazyLoad = require('yoho-jquery-lazyload');
9 12
@@ -13,6 +16,19 @@ var homePage = $('.home-page').data('page'), @@ -13,6 +16,19 @@ var homePage = $('.home-page').data('page'),
13 16
14 var yas = require('../common/data-yas'); 17 var yas = require('../common/data-yas');
15 18
  19 +const defTimeout = (time, type = 'default') => {
  20 + return timeout(time).then(()=> {
  21 + console.log(`${type} timeout`);
  22 + });
  23 +};
  24 +
  25 +(async function() {
  26 + await defTimeout(10000, 'await');
  27 + defTimeout(500);
  28 +
  29 + console.log('async end');
  30 +}());
  31 +
16 // 给头部js获取当前频道 32 // 给头部js获取当前频道
17 window.homePage = homePage; 33 window.homePage = homePage;
18 34
  1 +class Animal {
  2 + constructor() {
  3 + this.type = 'animal';
  4 + }
  5 + says(say = 'hi') {
  6 + setTimeout(() => {
  7 + console.log(`${this.type} says ${say}`);
  8 + }, 1000);
  9 + }
  10 +}
  11 +
  12 +class Cat extends Animal {
  13 + constructor() {
  14 + super();
  15 + this.type = 'cat';
  16 + }
  17 + setInfo(info) {
  18 + let {name, age, color} = info;
  19 +
  20 + name && (this.name = name);
  21 + age && (this.age = age);
  22 + color && (this.color = color);
  23 + }
  24 + infos() {
  25 + console.log(this);
  26 + }
  27 +}
  28 +
  29 +const timeout = (ms) => {
  30 + return new Promise((resolve) => {
  31 + setTimeout(resolve, ms);
  32 + });
  33 +};
  34 +
  35 +function* generator() {
  36 + yield 'hello';
  37 + yield 'generator';
  38 +}
  39 +
  40 +let cat = new Cat();
  41 +
  42 +cat.says();
  43 +cat.setInfo({name: 'mini', color: 'black'});
  44 +cat.infos();
  45 +
  46 +console.log([...generator()]);
  47 +
  48 +export {
  49 + cat,
  50 + timeout
  51 +};