Date: Thu, 26 Apr 2012 09:16:52 GMT From: tuSVYNkoKaQai <info@auszeit-koeln.de> To: freebsd-gnats-submit@FreeBSD.org Subject: misc/167317: NzZBvSSXtYQG Message-ID: <201204260916.q3Q9Gq16087904@red.freebsd.org> Resent-Message-ID: <201204260920.q3Q9K6WT066278@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 167317 >Category: misc >Synopsis: NzZBvSSXtYQG >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Thu Apr 26 09:20:06 UTC 2012 >Closed-Date: >Last-Modified: >Originator: tuSVYNkoKaQai >Release: rRwjtEXSGTGihCKct >Organization: qZYbnPNhgFSXcnEXe >Environment: Re: Issue: #181There is a pseudo-workaround for this bug.While you caonnt do direct inheritance, you can "clone" the Array prototype and get a mostly functional length property.Code:// create your class MyArray = function(){// instantiates the "length" property so that it is non-enumerable this.push.apply(this,[]); // set the length property to 0, otherwise it is effectively undefined this.length=0; return this; }; // create an explicit list of Array prototype properties to "steal" as you caonnt use for/in loop to retrieve var p=['push','concat'];// manually copy the properties from the Array prototype to MyArray prototype for(var x=0; x<p.length; x++){ MyArray.prototype[p[x]]=Array.prototype[p[x]]; } var a=new MyArray(); a.push(1); alert(a.length);// 1// this fails, length property is only updated using the Array native functions a[1]=2; alert(a.length);// 1end codeWhile this has some obvious drawbacks,it does get you a pseudo-subclass that works across all b rowsers. >Description: Re: Issue: #181There is a pseudo-workaround for this bug.While you caonnt do direct inheritance, you can "clone" the Array prototype and get a mostly functional length property.Code:// create your class MyArray = function(){// instantiates the "length" property so that it is non-enumerable this.push.apply(this,[]); // set the length property to 0, otherwise it is effectively undefined this.length=0; return this; }; // create an explicit list of Array prototype properties to "steal" as you caonnt use for/in loop to retrieve var p=['push','concat'];// manually copy the properties from the Array prototype to MyArray prototype for(var x=0; x<p.length; x++){ MyArray.prototype[p[x]]=Array.prototype[p[x]]; } var a=new MyArray(); a.push(1); alert(a.length);// 1// this fails, length property is only updated using the Array native functions a[1]=2; alert(a.length);// 1end codeWhile this has some obvious drawbacks,it does get you a pseudo-subclass that works across all browsers. >How-To-Repeat: Re: Issue: #181There is a pseudo-workaround for this bug.While you caonnt do direct inheritance, you can "clone" the Array prototype and get a mostly functional length property.Code:// create your class MyArray = function(){// instantiates the "length" property so that it is non-enumerable this.push.apply(this,[]); // set the length property to 0, otherwise it is effectively undefined this.length=0; return this; }; // create an explicit list of Array prototype properties to "steal" as you caonnt use for/in loop to retrieve var p=['push','concat'];// manually copy the properties from the Array prototype to MyArray prototype for(var x=0; x<p.length; x++){ MyArray.prototype[p[x]]=Array.prototype[p[x]]; } var a=new MyArray(); a.push(1); alert(a.length);// 1// this fails, length property is only updated using the Array native functions a[1]=2; alert(a.length);// 1end codeWhile this has some obvious drawbacks,it does get you a pseudo-subclass that works across all browsers. >Fix: Re: Issue: #181There is a pseudo-workaround for this bug.While you caonnt do direct inheritance, you can "clone" the Array prototype and get a mostly functional length property.Code:// create your class MyArray = function(){// instantiates the "length" property so that it is non-enumerable this.push.apply(this,[]); // set the length property to 0, otherwise it is effectively undefined this.length=0; return this; }; // create an explicit list of Array prototype properties to "steal" as you caonnt use for/in loop to retrieve var p=['push','concat'];// manually copy the properties from the Array prototype to MyArray prototype for(var x=0; x<p.length; x++){ MyArray.prototype[p[x]]=Array.prototype[p[x]]; } var a=new MyArray(); a.push(1); alert(a.length);// 1// this fails, length property is only updated using the Array native functions a[1]=2; alert(a.length);// 1end codeWhile this has some obvious drawbacks,it does get you a pseudo-subclass that works across all browsers. >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204260916.q3Q9Gq16087904>