cell-type
Version:
Prototypal(OLOO) inheritance algorithm.
125 lines (107 loc) • 3.95 kB
HTML
<html>
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/png" href="rsc/img/icon.png" />
<title>Just to run some tests</title>
</head>
<body>
<script src="src/Type.js"></script>
<!--<script src="test/prototypes/syntax.js"></script>-->
<script>
const $type = Symbol.for('cell-type');
const $attrs = Symbol.for('cell-type.attrs');
const $statics = Symbol.for('cell-type.statics');
/************************************************/
const Beginner = Type({properties: {
init(skill)
{
this._x = 0;
this.skills = ['html'];
if(skill) {this.skills.push(skill)}
return this
},
stringify()
{
return 'beginner'
},
get x()
{
return this._x - 1
},
set x(val)
{
return this._x = val + 2
},
staticMethod() {
"<$attrs static>"; // attributes can be used to supply additional functionality
{
return 'iamstatic'
}}
}});
const Specialist = Type({links: Beginner, properties: {
init(skill)
{
this._upper(skill);
this.skills.push('css');
return this
}
}});
// using the new keyword is also possible
const Expert = new Type({name: 'Expert', links: Specialist, properties: { // an additional name can be supplied for debugging purposes
init(skill)
{
this._x = 7;
this._upper(skill);
this.skills.push('js');
return this
},
stringify()
{
return 'expert'
},
get x()
{
return this._upper() - 3
},
set x(val)
{
this._x = this._upper(val) + 4
},
staticMethod() {
"<$attrs static enumerable !configurable>"; // attributes can be used to supply additional functionality
{
return this._upper()
}},
staticProp: {[$attrs]: 'static', value: 10}
}});
const e = Object.create(Expert).init('xhtml');
!function() {
const B = Type({
name: 'Beginner', properties: {
staticMethod()
{
"<$attrs static>";
return 'iamstatic'
}
}
});
// make sure it is able to find properties higher up the prototype chain
const S = Type({
name: 'Specialist', links: B, properties: {}
});
const E = Type({
name: 'Expert', links: S, properties: {
staticMethod()
{
"<$attrs static>";
return this._upper()
}
}
});
}()
/************************************************/
console.log('okay');
</script>
</body>
</html>