首页 > 代码库 > 201706180310_《 Javascript (ES6)给变量一个hash串》

201706180310_《 Javascript (ES6)给变量一个hash串》

(() => {

  //UUID Fn-1
  S4 = () => {
        return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
    };
  //UUID Fn-2
  guid = () => {
        let me = this;
        return (me.S4()+me.S4()+"-"+me.S4()+"-"+me.S4()+"-"+me.S4()+"-"+me.S4()+me.S4()+me.S4());
    };

  let oUuid = guid();
  let oArr = [‘Apple‘,‘Banana‘,‘Orange‘,‘Cheer‘];

   oArr.forEach((v,i,a) => {
        this.v = `${v}-${guid()}`;
        console.log(this.v);
    });
})();

// Apple-2b51f63b-45c8-070f-e3aa-71184a90eb3f
//Banana-e1ccf286-9d65-e7a0-0949-8bba1077554a
// Orange-a2e973fb-1c6f-6a82-c57d-fb7ae4143a1e
//Cheer-23d85cd0-3006-c1d3-fec0-79ba5458e5f6

 

201706180310_《 Javascript (ES6)给变量一个hash串》