Monday, 17 April 2023

javascript!

this

In a given function, this refers to the object that function is invoked from.

// handles creating C** once told the scheme
d.partor ||= DCpartor(d,'Con')
Inside DCparator:
// arrow functions don't provide their own this binding
whereas an arrow function retains the this value of the enclosing lexical context
return function (t,pi,c) {
// compat: this is the current d where this function is called
let d = this
            ...
We go on to clone d to recursions, d.partor uses its current d.

just variables

In javascript, class names are just variables, so you'd better call it something other than what you usually call it:
class TheC {}
class TheA extends TheC {}
Then we can do:
let C = new TheC()
ex(C,{t,y,c,sc})
Or:
let A = new TheA()
ex(A, C_(t))
Making a type-of-thing label for us to see amongst piles of objects in computer memory which get tossed, scanned, squished, swept etc around the surrealist office space of our demands.

Once noticed to be A or C, various other knowledge graphs (or assumptions) can apply.

Here we use the classes for nothing but their ability to label types of objects, out of band (separately) to the content of the objects (properties we iterate, etc).
We could alternatively apply a schema to the objects, or simply put the type label in our data model.
Putting the type label in an "unreachable" place (not iterable content of the object) makes a superficial distinction between "conscious" memory and that which lies on the page.
We are working on a new subject-to-object dialectic, so a language-agnostic functional firmament should allow more translation later. It is interesting that we can get lost and then try to recover sense systematically. I imagine this whole area will be wired for sound pretty soon, using misunderstandings and reinterpretations for creativity.
The low-levels of typology smoothly paved over.

post-hoc classimilation not advised

let A = C_(t)
Object.setPrototypeOf(A, TheA.prototype)
This blesses the A hash into TheA-dom.
If you look at TheA.prototype it is instanceof TheC!
with a .constructor = Function, which (in DevTools): 
(magic here?) identifies its source: class TheA extends TheC {} as its source,
and is also the value of TheA (without .prototype).

There's probably a simple explanation. Anyway,

Warning: Changing the [[Prototype]] of an object is, by the nature of how modern JavaScript engines optimize property accesses, currently a very slow operation in every browser and JavaScript engine. 

for in or for of

Arrays are a type of Object. This will print all the keys:

    let thi = [1,2,3]
thi.foo = 'fab'
for (let i in thi) {
console.log(i)
}

but for (let i of thi) { will:

  • avoid foo, because it uses an iterator from Array, which apparently only does array indices
  • iterate values, not keys

So given N=[C+] you can 

for (let C of N) {

And destructure given N=[{thing,act}+]

for (let {thing,act} of o_path(mind,['mind','thing','act'])) {

And to get key and value (iterating array or hash) at the same time:

for (let [k,v] of Object.entries(thi)) {

iterating anyway

In stylehouse, I usually write:

each iv N {

or

each nk,gk,v q {

which compile into for in loops iterating N.$i = v and q.$nk.$gk = v respectively.

They iterate keys then pluck out the value on an extra line, so it works on array or hash.

it's a beautiful world out there

conclusion

onward!

No comments:

Post a Comment