Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

前端常见问题 #12

Open
nianxiongdi opened this issue Aug 29, 2019 · 0 comments
Open

前端常见问题 #12

nianxiongdi opened this issue Aug 29, 2019 · 0 comments

Comments

@nianxiongdi
Copy link
Owner

nianxiongdi commented Aug 29, 2019

常见问题

1、创建一个新对象,如:var person = {};

2、新对象的_proto_属性指向构造函数的原型对象。

3、将构造函数的作用域赋值给新对象。(也所以this对象指向新对象)

4、执行构造函数内部的代码,将属性添加给person中的this对象。

5、返回新对象person。

var person = {};
person._proto_ = Person.prototype; //引用构造函数的原型对象
Person.call(person); //将构造函数的作用域给person,即:this值指向person

css

布局

react

node

app.use(cors({
  origin: function(ctx) {
    const whiteList = [, 'http://127.0.0.1:6001', ''];
    console.log(ctx.origin);
    if(ctx.origin in whiteList) {
      return ctx.origin;
    }

    return "http://0.0.0.0:9000";
  },
  credentials: true,
  "Access-Control-Allow-Credentials":"true",
 
}))
  • 字符串模版实现
function parseString(str, obj) {
  Object.keys(obj).forEach(key => {
    // str = str.replace(new RegExp(`{{${key}}}`,'g'), obj[key]);
    // str = str.replace(/`\$\{${key}\}`/g, obj[key])
    str = str.replace(new RegExp(`\{${key}\}`,'g'), obj[key]);
  });
  return str;
}
// const str = "{{name}}很厉name害{{name}},才{{age}}岁";
const str = "{name}很厉name害{name},才{age}岁";
const obj = { name: "qy", age: "18" };

console.log(parseString(str, obj));


function runTemplate(stringTemplate, row = {}) {
  return eval("`" + stringTemplate + "`");
}
console.log(runTemplate("年龄:${row.age}", { age: 20 })); // "年龄:20"
// 去除括号
// "${}${}${}".replace(/\$({)/g,function($, $1){return $1;})

算法

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant