-
Notifications
You must be signed in to change notification settings - Fork 1
/
mini_utopist.js
46 lines (39 loc) · 1.24 KB
/
mini_utopist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// mini_utopist, world's smallest JavaScript framework for conceptual programming.
// Inspired by the UTOPIST programming language.
// License: PUBLIC DOMAIN
// Stepan Mitkin
// DRAKON Labs
// https://drakon-editor.com/
function mini_utopist_def() {
function complexGetter(obj, fieldName, algorithm) {
var value = obj[fieldName]
if (value === null) {
value = algorithm.call(obj)
obj[fieldName] = value
}
return value
}
function simpleGetter(obj, fieldName, newValue) {
if (typeof newValue === "undefined") {
return obj[fieldName]
}
obj[fieldName] = newValue
}
this.addProperty = function(obj, propertyName, algorithm) {
var fieldName = "_" + propertyName
obj[fieldName] = null
if (algorithm) {
obj[propertyName] = function() {
return complexGetter(this, fieldName, algorithm)
}
} else {
obj[propertyName] = function(newValue) {
return simpleGetter(this, fieldName, newValue)
}
}
}
}
mini_utopist = new mini_utopist_def()
if (typeof exports != "undefined") {
exports.addProperty = mini_utopist.addProperty
}