bugease.js - Bugs: bug #38255, Property assignments of extended...

 
 

bug #38255: Property assignments of extended prototypes (non-class)

Submitter:  Mike Gerwitz <mikegerwitz>
Submitted:  Mon 04 Feb 2013 06:14:25 PM UTC
   
 
Category:  Core Severity:  4 - Important
Priority:  5 - Normal Item Group:  Development
Status:  Confirmed Privacy:  Public
Assigned to:  mikegerwitz Percent Complete:  0%
Open/Closed:  Open Release:  * 0.1.0
Operating System:  None Planned Release: 
Fixed Release:  Runtime Environment:  * All
Runtime Environment Version: 
Keywords:  inheritance, prototypes
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 04 Feb 2013 06:14:25 PM UTC, original submission:  

Consider this situation:

function Foo()
{
}

Foo.prototype.bar = function( val )
{
  this.foo = val;
}

var Foo2 = Class( 'Foo2' ).extend( Foo,
{
  'public setBar': function( val )
  {
    this.bar( val );
  },

  'public getBar': function()
  {
    return this.foo;
  },
} );

Now, consider that we have:

var foo = Foo2();
foo.bar( 'moo' );
foo.foo // "moo"
foo.getBar() // "moo"

foo.setBar( 'baz' );
foo.foo // "moo"
foo.getBar() // "baz"

The problem is that 'foo' isn't defined as a property on the prototype---it is simply assigned during a method call. This is a problem because ease.js therefore does not create a proxy to it and, as such, the context (bound to 'this') is the private visibility object when Foo.bar() is called within the scope of the class. However, when it's called outside the scope of the class, it is the public visibility object.

With the understanding that these properties would be implicitly public in pure ECMAScript, it may suffice to simply have ease.js wrap each method of the prototype being inherited (if it recognizes that it is not a class), which would then ensure that 'this' references the public visibility object. Of course, that would mean that the supertype would not have access to protected members.

Mike Gerwitz <mikegerwitz>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mikegerwitz (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.14-f13d.
    Corresponding source code