/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* * *Date:16Dec2002 *SUMMARY:Testing|with(x){functionf(){}}|when|x.f|alreadyexists *Seehttp://bugzilla.mozilla.org/show_bug.cgi?id=185485 * *Theideaisthis:if|x|doesnotalreadyhaveapropertynamed|f|, *a|with|statementcannotbeusedtodefineone.See,forexample, * *http://bugzilla.mozilla.org/show_bug.cgi?id=159849#c11 *http://bugzilla.mozilla.org/show_bug.cgi?id=184107 * * *However,if|x|alreadyhasaproperty|f|,a|with|statementcanbe *usedtomodifythevalueitcontains: * *with(x){f=1;} * *Thisshouldworkevenifweusea|var|statement,likethis: * *with(x){varf=1;} * *However,itshouldNOTworkifweusea|function|statement,likethis: * *with(x){functionf(){}} * *Instead,thisshouldnewlydefineafunctionfinglobalscope. *Seehttp://bugzilla.mozilla.org/show_bug.cgi?id=185485 *
*/ //----------------------------------------------------------------------------- var UBound = 0; var BUGNUMBER = 185485; var summary = 'Testing |with (x) {function f() {}}| when |x.f| already exists'; var status = ''; var statusitems = []; var actual = ''; var actualvalues = []; var expect= ''; var expectedvalues = [];
var x = { f:0, g:0 };
with (x)
{
f = 1;
}
status = inSection(1);
actual = x.f;
expect = 1;
addThis();
with (x)
{ var f = 2;
}
status = inSection(2);
actual = x.f;
expect = 2;
addThis();
/* *Useofafunctionstatementunderthewith-blockshouldnotaffect *thelocalproperty|f|,butdefineafunction|f|inglobalscope-
*/
with (x)
{ function f() {}
}
status = inSection(3);
actual = x.f;
expect = 2;
addThis();
status = inSection(4);
actual = typeofthis.f;
expect = 'function';
addThis();
/* *Compareuseoffunctionexpressioninsteadoffunctionstatement. *Noteitisimportantthat|x.g|alreadyexists.Otherwise,this *wouldnewlydefine|g|inglobalscope-
*/
with (x)
{ var g = function() {}
}
status = inSection(5);
actual = x.g.toString();
expect = (function() {}).toString();
addThis();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.