Loading ...
Sorry, an error occurred while loading the content.

forin bug

Expand Messages
  • Sean Soria
    The following code: /*jslint maxerr: 50, maxlen: 80, indent: 4 */ var extend = function (o, p) {     use strict ;     var f;     for (f in p) {      
    Message 1 of 3 , Jun 10, 2011
    • 0 Attachment
      The following code:
      /*jslint maxerr: 50, maxlen: 80, indent: 4 */
      var extend = function (o, p) {
          'use strict';

          var f;
          for (f in p) {
              if (o.hasOwnProperty(f)) {
                  o[f] = p[f];
              }
          }
          return o;
      };

      generates the following error:
      Problem at line 8 character 5: The body of a for in should be wrapped
      in an if statement to filter unwanted properties from the prototype.

      Is this a bug? The body of the for in statement is obviously wrapped
      in an if statement.

      Sean
    • Marc Spoor
      you should probably use p.hasOwnProperty, not o.hasOwnProperty... ... [Non-text portions of this message have been removed]
      Message 2 of 3 , Jun 10, 2011
      • 0 Attachment
        you should probably use p.hasOwnProperty, not o.hasOwnProperty...

        On Sat, Jun 11, 2011 at 10:36, Sean Soria <sean.soria@...> wrote:

        >
        >
        > The following code:
        > /*jslint maxerr: 50, maxlen: 80, indent: 4 */
        > var extend = function (o, p) {
        > 'use strict';
        >
        > var f;
        > for (f in p) {
        > if (o.hasOwnProperty(f)) {
        > o[f] = p[f];
        > }
        > }
        > return o;
        > };
        >
        > generates the following error:
        > Problem at line 8 character 5: The body of a for in should be wrapped
        > in an if statement to filter unwanted properties from the prototype.
        >
        > Is this a bug? The body of the for in statement is obviously wrapped
        > in an if statement.
        >
        > Sean
        >
        >


        [Non-text portions of this message have been removed]
      • Sean Soria
        that ll do it. thanks marc.
        Message 3 of 3 , Jun 10, 2011
        • 0 Attachment
          that'll do it. thanks marc.

          On Fri, Jun 10, 2011 at 3:52 PM, Marc Spoor <marc.spoor@...> wrote:
          > you should probably use p.hasOwnProperty, not o.hasOwnProperty...
          >
          > On Sat, Jun 11, 2011 at 10:36, Sean Soria <sean.soria@...> wrote:
          >
          >>
          >>
          >> The following code:
          >> /*jslint maxerr: 50, maxlen: 80, indent: 4 */
          >> var extend = function (o, p) {
          >>     'use strict';
          >>
          >>     var f;
          >>     for (f in p) {
          >>         if (o.hasOwnProperty(f)) {
          >>             o[f] = p[f];
          >>         }
          >>     }
          >>     return o;
          >> };
          >>
          >> generates the following error:
          >> Problem at line 8 character 5: The body of a for in should be wrapped
          >> in an if statement to filter unwanted properties from the prototype.
          >>
          >> Is this a bug? The body of the for in statement is obviously wrapped
          >> in an if statement.
          >>
          >> Sean
          >>
          >>
          >
          >
          > [Non-text portions of this message have been removed]
          >
          >
          >
          > ------------------------------------
          >
          > Yahoo! Groups Links
          >
          >
          >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.