class Utils { //渲染底部 footer() { var html = ` ` $("body").insertAdjacentHTML("beforeend", html); } //渲染广场页item item(father, data) { //console.log(data) father.innerHTML = "" data.forEach(v => { father.innerHTML += `

${v.thing_title}

${v.user_name}
` }) } // item(father, data) { // console.log(data) // father.innerHTML = "" // data.forEach(v => { // father.innerHTML += ` //
//
// //
//

${v.thing_title}

//
// // ${v.user_name} //
//
// ` // }) // } title(text = "", leftIcon = "",) { var html = `
${leftIcon} ${text}
` $("body").insertAdjacentHTML("beforeend", html); click(".icon-fanhui", () => { history.back() }) } click(className, callback) { _(className).forEach((v, i) => v.onclick = () => callback(v, i)) } query(name) { let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); let r = window.location.search.substr(1).match(reg); if (r != null) { return decodeURIComponent(r[2]); }; return null; } cover() { // 对map进行重写 // map的实现原理 // function a(callback) { // return callback(v).toString() // } // var c = a( function (v) { // return "v" // } ) Array.prototype.forH = function (callback) { var res = [] for (var index = 0; index < this.length; index++) { res.push(callback(this[index])) } return res.toString().replaceAll(",", "") } // 其他很多重写 } $(className) { return document.querySelector(className) } _(className) { return document.querySelectorAll(className) } } var { footer, $, _, query, cover, click, item, items, title } = new Utils(); cover()