< The Science of Programming < SwayPresentations < Objects
Class and Object Components
Class component: shared by all instances
Object component: unique for each instance
Could use a global variable...
var shared_count = 0;
function z()
{
var count = 0;
shared_count += 1;
count += 1;
this;
}
function x()
{
extends(z());
}
inspect(x() . shared_count); inspect(x() . count); inspect(x() . shared_count);
Results are as expected:
x() . shared_count is 1 x() . count is 1 x() . shared_count is 3
Not very satisfying...
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.