Inheritance and Scopes in Egg

JavaScript — Inheritance, delegation patterns and Object linking

Scopes in Egg

This figure illustrates the chain of environment objects for the code trace explained in the video class below

corresponding to the code

do(
  define(sum,  # function
    fun(nums, other,
      do(
         print(other),
         define(i, 0),
         define(sum, 0),
         while(<(i, length(nums)),
           do(define(sum, +(sum, element(nums, i))),
              define(i, +(i, 1))
           )
         ),
         sum
      )
   )
 ),
 print(sum(array(1, 2, 3), 4))
)

when inside the generated function for sum

The proto

… Most modern browsers, however, do offer property available called __proto__ (that’s 2 underscores either side), which contains the object’s constructor’s prototype object. For example, try localenv.__proto__ and localenv.__proto__.__proto__ to see what the prototype chain looks like in code!