相关疑难解决方法(0)

Javascript原型与一般功能 - 性能/可读性

所以我写了这些测试,看看使用原型会有多快...

function User() {
    return {
        name: "Dave",
        setName: function(n) {
            this.name = n;
        },
        getName: function() {
            return this.name;
        }
    };
}

function UserPrototype() {
    if (!(this instanceof UserPrototype)) return new UserPrototype();
    this.name = "Dave";
}
UserPrototype.prototype.getName = function() {
    return this.name;
};
UserPrototype.prototype.setName = function(n) {
    this.name = n;
};

function setName(obj,name)
{
    obj.name = name;
}
function getName(obj)
{
    return obj.name;
}

//Test 1
var c = 10000000;
var tstart = 0;
var tend = 0;
tstart …
Run Code Online (Sandbox Code Playgroud)

javascript prototype

6
推荐指数
1
解决办法
1008
查看次数

标签 统计

javascript ×1

prototype ×1