es6 类

class Person {
  constructor(name){
    this.name = name
  }

  hello(){
    console.log('Hello, my name is ' + this.name + '.');
  }
}

var xiaoMing = new Person('xiaoMing');
xiaoMing.hello() // Hello, my name is xiaoMing.

例如:

export default class Singer{
  constructor({id,name}){
    this.id=id;
    this.name=name;
    this.avatar= `https://y.gtimg.cn/music/photo_new/T001R300x300M000${id}.jpg?max_age=2592000`
  }
}


 normalLizeSinger(list){
        let map={
          hot:{
            title:HOT_NAME,
            items:[]
          }
        }
        list.forEach((item,index)=>{
           if(index<HOT_SINGER_LEN){
             map.hot.items.push(
               new Singer({
                 id:item.Fsinger_mid,
                 name:item.Fsinger_name,}))
           }
           const key=item.Findex;
           if(!map[key]){
             map[key]={
               title:key,
               items:[],
             }
           }
          map[key].items.push( new Singer({
            id:item.Fsinger_mid,
            name:item.Fsinger_name,}))
        })
        // 为了得到有序列表,我们需要处理map
         let hot=[];
        let ret=[];
        for(let key in map){
          let val = map[key];
          if(val.title.match(/a-zA-Z/)){
            ret.push(val);
          }else if(val.title===HOT_NAME){
            hot.push(val);
          }
        }
        ret.sort((a,b)=>{
          return a.title.charCodeAt(0)-b.title.charCodeAt(0)
        })
      },

猜你喜欢

转载自blog.csdn.net/pansuyong/article/details/81808514