New issue
 Projects > js > Issues > Refactor #3985

Refactor arguments.length test with undefined check

Refactor #3985 [Closed]
pandamicro 2014-02-10 14:36 . Updated almost 3 years ago

Two advantage:
1. Faster: http://jsperf.com/undefined-argument-vs-arguments-length
2. More compatible

Ex:

// @override
setContentSize: function(size, height) {
    // Do sth
    cc.Node.prototype.setContentSize.call(this, size, height);
}

With arguments.length, even if original height parameter is not given, the super function call will pass two parameters, so we must do multiply check

setContentSize: function(size, height) {
    // Do sth
    if(arguments.length === 2) cc.Node.prototype.setContentSize.call(this, size, height);
    else cc.Node.prototype.setContentSize.call(this, size);
}

Pretty ugly

pandamicro 2014-02-12 05:56
  • Status changed from New to Closed
  • % Done changed from 0 to 100

Atom PDF

Status:Closed
Start date:2014-02-10
Priority:High
Due date:
Assignee:pandamicro
% Done:

100%

Category:-
Target version:v3.0 alpha

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.