Home  >  Q&A  >  body text

javascript - What are the advantages of these two ways of writing functions?

I feel that the second one is more troublesome than the first one. Are there any advantages?

三叔三叔2663 days ago787

reply all(2)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-07-05 11:00:44

    When the CheckObject object has many attributes, the entire function body is too long, which affects the reading of the code. In the second method, each attribute of the object is a method, which is short and concise, highly readable, and the code logic is the same. Of

    reply
    0
  • 代言

    代言2017-07-05 11:00:44

    I don’t feel that the second one has any obvious advantages. I like the first one, or else the second one should be changed like this

    var CheckObject = function(){};
    CheckObject.prototype.checkName = function() {
    
    }
    var check = new CheckObject();
    check.checkName();

    reply
    0
  • Cancelreply