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

Re: [jslint] Re: Can we please lose the trailing whitespace and "this" restriction?

Expand Messages
  • Jean-Charles Meyrignac
    ... In my company, we use SVN+CCNet+Nant/MsBuild If you have 100+ developers, you necessarily have a continuous build, and I m 100% sure that you can script
    Message 1 of 22 , Nov 17, 2011
    • 0 Attachment
      On Thu, Nov 17, 2011 at 11:48 PM, Michael Mikowski <z_mikowski@...>wrote:

      > **
      >
      >
      > Our official JSLint utility is kept in SCMS, and changes about once per
      > quarter. It is almost always adjusted to meet our standards that deviate
      > from the JSLint way.
      >
      > +1
      In my company, we use SVN+CCNet+Nant/MsBuild

      If you have 100+ developers, you necessarily have a continuous build, and
      I'm 100% sure that you can script your own build automation.
      When people commit their source, the source could be automatically cleaned
      (or you can clean it once, and force the developers to follow the rules).
      Then, your build process should parse JS sources with JSLint, and block the
      build if there are errors.
      The goal of breaking the build is to force developers to acquire good
      programming habits. It's very difficult to change habits, because nobody
      wants to follow new rules.
      Once the sources have been checked against your coding rules, the process
      should run some unit tests, to validate that the basic functions are not
      broken.

      I agree that this solution is quite "brute", but you should see JsLint as
      an ally instead of an enemy.
      Personally, I tended to fight against software until I stopped trying to
      force my wishes on it, and everything went smoothly afterwards.

      Alternatively, you can use a modified version of JsLint in your build
      process, and upgrade your local version every 6 months, as the parent post
      explained.

      JC


      [Non-text portions of this message have been removed]
    • Nagy Endre
      Hi everyone, maybe it s a little offtopic sorry, but can anyone explain why this inside the o object is refer to window ? Why it s not refer to the o
      Message 2 of 22 , Nov 18, 2011
      • 0 Attachment
        Hi everyone, maybe it's a little offtopic sorry, but can anyone explain why "this" inside the "o" object is refer to window ?
        Why it's not refer to the "o" object if we are inside there? I want to access from the returned object in function "f" the "o.p" property without using "o". Thanks!

        var p = 2,
            o  =  {
                p: "a",
                f: (function (m) {
                    return {
                        l: m.p
                    };
                }(this))
            };

        p = o.f.l;

        Endre


        [Non-text portions of this message have been removed]
      • z_mikowski@yahoo.com
        Javascript does not provide block scope, only functional scope. Therefore the this in your code takes the value as provided to the enclosing function. You
        Message 3 of 22 , Nov 18, 2011
        • 0 Attachment
          Javascript does not provide block scope, only functional scope. Therefore the 'this' in your code takes the value as provided to the enclosing function. You could use the module pattern to get the results you are seeking, e.g.

          var o = function (){
          // private stuff
          return {
          p : "a",
          // rest of object here
          };
          };



          Nagy Endre <forewer2000@...> wrote:

          >
          >Hi everyone, maybe it's a little offtopic sorry, but can anyone explain why "this" inside the "o" object is refer to window ?
          >Why it's not refer to the "o" object if we are inside there? I want to access from the returned object in function "f" the "o.p" property without using "o". Thanks!
          >
          >var p = 2,
          >    o  =  {
          >        p: "a",
          >        f: (function (m) {
          >            return {
          >                l: m.p
          >            };
          >        }(this))
          >    };
          >
          >p = o.f.l;
          >
          >Endre
          >
          >
          >[Non-text portions of this message have been removed]
          >


          [Non-text portions of this message have been removed]
        • Rob Richardson
          Try this: var p = 2, o = { p: a }; o.f = (function (m) { return { l: m.p }; }(o)); p = o.f.l; Or this: var p = 2, o = { p: a }; o.prototype.f =
          Message 4 of 22 , Nov 18, 2011
          • 0 Attachment
            Try this:

            var p = 2,
            o = {
            p: "a"
            };
            o.f = (function (m) {
            return {
            l: m.p
            };
            }(o));
            p = o.f.l;

            Or this:

            var p = 2,
            o = {
            p: "a"
            };
            o.prototype.f = function () {
            return {
            l: this.p
            };
            };
            p = o.f.l;

            Rob


            -----Original Message-----
            From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On
            Behalf Of Nagy Endre
            Sent: Friday, November 18, 2011 7:13 AM
            To: jslint_com@yahoogroups.com
            Subject: [jslint] this question




            Hi everyone, maybe it's a little offtopic sorry, but can anyone explain why
            "this" inside the "o" object is refer to window ?
            Why it's not refer to the "o" object if we are inside there? I want to
            access from the returned object in function "f" the "o.p" property without
            using "o". Thanks!

            var p = 2,
            o = {
            p: "a",
            f: (function (m) {
            return {
            l: m.p
            };
            }(this))
            };

            p = o.f.l;

            Endre

            [Non-text portions of this message have been removed]
          • stauren
            I don t think this is about block scope or functional sope. This is probably because the function is executed when the script is being parsed, at which time
            Message 5 of 22 , Nov 20, 2011
            • 0 Attachment
              I don't think this is about block scope or functional sope. This is
              probably because the function is executed when the script is being parsed,
              at which time the outer object is not fully established, so the the keyword
              'this' points to the window object.

              Another funny aspect of javascript.

              ---
              stauren (畅)
              blog : http://stauren.net
              email : stauren@...


              On Sat, Nov 19, 2011 at 12:19 AM, <z_mikowski@...> wrote:

              > **
              >
              >
              > Javascript does not provide block scope, only functional scope. Therefore
              > the 'this' in your code takes the value as provided to the enclosing
              > function. You could use the module pattern to get the results you are
              > seeking, e.g.
              >
              > var o = function (){
              > // private stuff
              > return {
              > p : "a",
              > // rest of object here
              > };
              > };
              >
              >
              > Nagy Endre <forewer2000@...> wrote:
              >
              > >
              > >Hi everyone, maybe it's a little offtopic sorry, but can anyone explain
              > why "this" inside the "o" object is refer to window ?
              > >Why it's not refer to the "o" object if we are inside there? I want to
              > access from the returned object in function "f" the "o.p" property without
              > using "o". Thanks!
              > >
              > >var p = 2,
              > > o = {
              > > p: "a",
              > > f: (function (m) {
              > > return {
              > > l: m.p
              > > };
              > > }(this))
              > > };
              > >
              > >p = o.f.l;
              > >
              > >Endre
              > >
              > >
              > >[Non-text portions of this message have been removed]
              > >
              >
              > [Non-text portions of this message have been removed]
              >
              >
              >


              [Non-text portions of this message have been removed]
            • Nagy Endre
              Yes, i realized that in {a: this} the value of a is the window value, not what we expect, because at runtime probably the object is not created yet, so
              Message 6 of 22 , Nov 21, 2011
              • 0 Attachment
                Yes, i realized that in {a: this} the value of "a" is the "window" value, not what we expect, because at runtime probably the object is not created yet,
                so only a method that is called later could have the correct "this" value.

                I think it would be great if JSLINT could display an error in this situation like:
                var o = {
                    a : this;
                };

                Because i think is there a little confusion here what will be the value of "this".



                ________________________________
                From: stauren <liuch.pku@...>
                To: jslint_com@yahoogroups.com
                Sent: Monday, November 21, 2011 9:49 AM
                Subject: Re: [jslint] this question


                 
                I don't think this is about block scope or functional sope. This is
                probably because the function is executed when the script is being parsed,
                at which time the outer object is not fully established, so the the keyword
                'this' points to the window object.

                Another funny aspect of javascript.

                ---
                stauren (畅)
                blog : http://stauren.net
                email : stauren@...

                On Sat, Nov 19, 2011 at 12:19 AM, <z_mikowski@...> wrote:

                > **
                >
                >
                > Javascript does not provide block scope, only functional scope. Therefore
                > the 'this' in your code takes the value as provided to the enclosing
                > function. You could use the module pattern to get the results you are
                > seeking, e.g.
                >
                > var o = function (){
                > // private stuff
                > return {
                > p : "a",
                > // rest of object here
                > };
                > };
                >
                >
                > Nagy Endre <forewer2000@...> wrote:
                >
                > >
                > >Hi everyone, maybe it's a little offtopic sorry, but can anyone explain
                > why "this" inside the "o" object is refer to window ?
                > >Why it's not refer to the "o" object if we are inside there? I want to
                > access from the returned object in function "f" the "o.p" property without
                > using "o". Thanks!
                > >
                > >var p = 2,
                > > o = {
                > > p: "a",
                > > f: (function (m) {
                > > return {
                > > l: m.p
                > > };
                > > }(this))
                > > };
                > >
                > >p = o.f.l;
                > >
                > >Endre
                > >
                > >
                > >[Non-text portions of this message have been removed]
                > >
                >
                > [Non-text portions of this message have been removed]
                >
                >
                >

                [Non-text portions of this message have been removed]




                [Non-text portions of this message have been removed]
              Your message has been successfully submitted and would be delivered to recipients shortly.