开发者

Whats the quickest way to get rid of all the properties of a an object in javascript?

I have an on object like so

var obj = {};
function set()
{
   obj.x1 = 20;
   obj.y1 = 35;
   obj.x2 = 60;
   obj.y2 = 55;
   ...
}
开发者_如何学Go

Whats the quickest way to delete/reset all of the properties of obj?


for (p in obj) {
    if (obj.hasOwnProperty(p)) {
        delete obj[p];
    }
}

If you only have one reference to the object, then replacing it with a new one would be faster.

obj = {};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜