From 8c27075aea4c6e1d4f81d77f9e833c24e37eeb54 Mon Sep 17 00:00:00 2001 From: Geo Halkiadakis Date: Mon, 25 Nov 2024 19:44:14 +0200 Subject: impelement requirejs demo; introduce esm demo --- t.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 t.js (limited to 't.js') diff --git a/t.js b/t.js new file mode 100644 index 0000000..0b19957 --- /dev/null +++ b/t.js @@ -0,0 +1,50 @@ + +const personFactory = (setup) => { + + let person = { + + who: { + // name: '', + // surname: '', + // age: 0, + // job: 'unpemployed' + }, + + init: function (json) { + // this.who.name = json.name; + // this.who.surname = json.surname; + // this.who.job = json.job; + // this.who.age = json.age; + this.who = json; + return this; + }, + + whoami: function() { + let who = this.who; + return `${who.name} ${who.surname}, ${who.job}, ${who.age} years old`; + }, + + setJob: function (job) { + this.who.job = job; + return this; + }, + + grow: function(years) { + if (years == null) this.who.age++; + else this.who.age += years; + return this; + } + + } + + return person.init(setup) + +} + +geo = personFactory({ + name: 'George', surname: 'Xalkis', age: 56 +}) +console.log('@@init', geo.whoami()); + +geo.setJob('developer').grow(4); +console.log(geo.whoami()); \ No newline at end of file -- cgit v1.2.3