< The Science of Programming < SwayPresentations < Objects
Class and Object Components, continued
Here's an attempt...
var z =
{
var z_shared = { var count = 0; this; };
function z()
{
var shared = z_shared;
var count = 0;
shared . count += 1;
count += 1;
this;
}
};
function x()
{
extends(z());
}
Testing...
inspect(x() . shared . count); inspect(x() . count); inspect(x() . shared . count);
Output is as desired:
x() . shared . count is 1 x() . count is 1 x() . shared . count is 3
The beauty of concatenation...
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.