{"size": 588, "ext": "js", "max_stars_repo_path": "src/new.js", "max_stars_repo_name": "looprandom/js-", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/new.js", "max_issues_repo_name": "looprandom/js-", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/new.js", "max_forks_repo_name": "looprandom/js-", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.52, "max_line_length": 51, "alphanum_fraction": 0.6666666667}
/*
    new 运算符
    1 在堆内存中创建一个空间存放一个空白对象
    2 将constructor的prototype赋值给空白对象的[[proto]]属性
    3 执行constructor，并把this指向新建的空白对象
    4 若constructor的返回值为object则返回该object,否则返回新建的空白对象
*/

function myNew(fn, ...args) {
    console.log(fn instanceof Function)
    if (!(fn instanceof Function))
        throw `${fn} is no a constructor`
    let ob = {}
    ob.__proto__ = fn.prototype
    let ret = fn.apply(ob, args)
    return ret instanceof Object ? ret : ob
}

function Person(name, age) {
    this.name = name
    this.age = age
}

console.log(myNew(Person, '张三', '18'))
console.log(myNew(1))