abstract 类和 abstract 方法
特点:
abstract类不能使用new运算符创建对象
abstract类中可以有abstract方法,也可以没有(不是abstract 的类中不能写abstract方法)
生成通用唯一标识符:
generateNewGuid:function () {
function randomDigit() {
if (crypto && crypto.getRandomValues) {
var rands = new Uint8Array(1);
crypto.getRandomValues(rands);
return (rands[0] % 16).toString(16);
} else {
return ((Math.random() * 16) | 0).toString(16);
}
};
var crypto = window.crypto || window.msCrypto;
return 'xxxxxxxxxxxx4xxx8xxxxxxxxxxxxxxx'.replace(/x/g, randomDigit).toUpperCase();
},
输出结果
ts写法:
export function generateNewGuid() {
function randomDigit() {
if (window.crypto) {
const rands = new Uint8Array(1);
window.crypto.getRandomValues(rands);
return (rands[0] % 16).toString(16);
} else {
return ((Math.random() * 16) | 0).toString(16);
}
};
return 'xxxxxxxxxxxx4xxx8xxxxxxxxxxxxxxx'.replace(/x/g, randomDigit).toUpperCase();
}