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

Re: Type confusion error when different objects' properties have different types

Expand Messages
  • bartman1c
    so, it will be easier to understand write different arrays that hold redirects to random generated names of stuff in objects, sweet. Turning off jslint would
    Message 1 of 12 , Jul 2, 2011
    • 0 Attachment
      so, it will be easier to understand write different arrays that hold redirects to random generated names of stuff in objects, sweet. Turning off jslint would work better o.o
    • s_lubowsky
      Dont want to beat a dead horse, but I agree completely. While I would like to keep type confusion checking on for cases where it really is useful, I find that
      Message 2 of 12 , Jul 7, 2011
      • 0 Attachment
        Dont want to beat a dead horse, but I agree completely. While I would like to keep type confusion checking on for cases where it really is useful, I find that the new restrictive policy not allowing same named identifiers on different objects to have different types much too restrictive. I simply turn it off for all my files.

        Perhaps there could be two levels of type confusion, one that honored object scoping as a more restrictive one that didnt?

        Thanks
        Stephen


        --- In jslint_com@yahoogroups.com, Erik Eckhardt <erik@...> wrote:
        >
        > The two `prop`s are properties of different objects. I don't see why that is
        > type confusion because property names do not have meaning beyond the object
        > they belong in. They're not variables scoped to a function, so identifying
        > them as a clash within a function is to promote them to a bigger something
        > they simply aren't.
        >
        > var obj1 = {
        > ______doit : true
        > ___},
        > obj2 = {
        > ______doit : function() {//do something}
        > }
        > if (obj1.doit) {
        > obj2.doit();
        > }
        >
        > There is no conflict here in usage. Names of variables are not arguably
        > immutable in meaning when they don't share the same scope. It's legitimate
        > for doit to be a boolean in one case signifying whether to do it, and to be
        > a function in another to actually carry it out. What if these come from
        > different libraries that we don't have control over? Our code is clean as a
        > whistle, both libraries properly scoped themselves as modules, there
        > shouldn't be a problem.
        >
        > If you would not throw an type confusion error in the following code
        > (because the two `doit`s don't belong to the same scope) then I don't see
        > how it should apply across object boundaries either:
        >
        > var doit = true;
        > function x() {
        > ___this.doit = function () {//do something};
        > ___doit = false;
        > ___this.doit();
        > }
        >
        >
        > On Mon, Jun 20, 2011 at 6:00 AM, Douglas Crockford <douglas@...>wrote:
        >
        > > **
        > >
        > >
        > > The property .prop is being used as both a string and a function.
        > >
        > >
        > > On 6/20/2011 2:34 AM, Jordan wrote:
        > > > The following code:
        > > >
        > > > /*global other_object */
        > > > /*global other_object */
        > > > var obj = {
        > > > callback: function (data) {
        > > > if (typeof (data.prop) === 'string') {
        > > > other_object.prop('Property: ' + data.prop);
        > > > }
        > > > }
        > > > };
        > > >
        > > > produces the following error:
        > > >
        > > > Problem at line 5 character 46: Type confusion: string and function.
        > > > other_object.prop('Property: ' + data.prop);
        > > >
        > > > This only seems to happen when "other_object" is listed as a global and
        > > defined in another file - when I define it in the same file there is no
        > > error. In addition, if I replace the `if` condition with "if (typeof
        > > (data.prop) === 'string') {" (ie, even more explicitly defining the type of
        > > `data.prop`) it produces the same JSLint error.
        > > >
        > > > - Jordan
        > > >
        > > >
        > > >
        > > > ------------------------------------
        > > >
        > > > Yahoo! Groups Links
        > > >
        > > >
        > > >
        > > >
        > >
        > >
        > >
        >
        >
        > [Non-text portions of this message have been removed]
        >
      • Jérôme DESPATIS
        +1 For now, I run JSLint with tolerate type confusion for all my .js, and then a second turn with type confusion and see file by file if I consider this type
        Message 3 of 12 , Jul 7, 2011
        • 0 Attachment
          +1

          For now, I run JSLint with tolerate type confusion for all my .js, and
          then a second turn with type confusion and see file by file if I
          consider this type confusion really an error or not...

          Le 07/07/2011 15:32, s_lubowsky a écrit :
          >
          > Dont want to beat a dead horse, but I agree completely. While I would
          > like to keep type confusion checking on for cases where it really is
          > useful, I find that the new restrictive policy not allowing same named
          > identifiers on different objects to have different types much too
          > restrictive. I simply turn it off for all my files.
          >
          > Perhaps there could be two levels of type confusion, one that honored
          > object scoping as a more restrictive one that didnt?
          >
          > Thanks
          > Stephen
          >
          > --- In jslint_com@yahoogroups.com
          > <mailto:jslint_com%40yahoogroups.com>, Erik Eckhardt <erik@...> wrote:
          > >
          > > The two `prop`s are properties of different objects. I don't see why
          > that is
          > > type confusion because property names do not have meaning beyond the
          > object
          > > they belong in. They're not variables scoped to a function, so
          > identifying
          > > them as a clash within a function is to promote them to a bigger
          > something
          > > they simply aren't.
          > >
          > > var obj1 = {
          > > ______doit : true
          > > ___},
          > > obj2 = {
          > > ______doit : function() {//do something}
          > > }
          > > if (obj1.doit) {
          > > obj2.doit();
          > > }
          > >
          > > There is no conflict here in usage. Names of variables are not arguably
          > > immutable in meaning when they don't share the same scope. It's
          > legitimate
          > > for doit to be a boolean in one case signifying whether to do it,
          > and to be
          > > a function in another to actually carry it out. What if these come from
          > > different libraries that we don't have control over? Our code is
          > clean as a
          > > whistle, both libraries properly scoped themselves as modules, there
          > > shouldn't be a problem.
          > >
          > > If you would not throw an type confusion error in the following code
          > > (because the two `doit`s don't belong to the same scope) then I
          > don't see
          > > how it should apply across object boundaries either:
          > >
          > > var doit = true;
          > > function x() {
          > > ___this.doit = function () {//do something};
          > > ___doit = false;
          > > ___this.doit();
          > > }
          > >
          > >
          > > On Mon, Jun 20, 2011 at 6:00 AM, Douglas Crockford <douglas@...>wrote:
          > >
          > > > **
          > > >
          > > >
          > > > The property .prop is being used as both a string and a function.
          > > >
          > > >
          > > > On 6/20/2011 2:34 AM, Jordan wrote:
          > > > > The following code:
          > > > >
          > > > > /*global other_object */
          > > > > /*global other_object */
          > > > > var obj = {
          > > > > callback: function (data) {
          > > > > if (typeof (data.prop) === 'string') {
          > > > > other_object.prop('Property: ' + data.prop);
          > > > > }
          > > > > }
          > > > > };
          > > > >
          > > > > produces the following error:
          > > > >
          > > > > Problem at line 5 character 46: Type confusion: string and function.
          > > > > other_object.prop('Property: ' + data.prop);
          > > > >
          > > > > This only seems to happen when "other_object" is listed as a
          > global and
          > > > defined in another file - when I define it in the same file there
          > is no
          > > > error. In addition, if I replace the `if` condition with "if (typeof
          > > > (data.prop) === 'string') {" (ie, even more explicitly defining
          > the type of
          > > > `data.prop`) it produces the same JSLint error.
          > > > >
          > > > > - Jordan
          > > > >
          > > > >
          > > > >
          > > > > ------------------------------------
          > > > >
          > > > > Yahoo! Groups Links
          > > > >
          > > > >
          > > > >
          > > > >
          > > >
          > > >
          > > >
          > >
          > >
          > > [Non-text portions of this message have been removed]
          > >
          >
          >


          --
          Jérôme Despatis
          jerome@...



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