home / skills / copyleftdev / sk1llz / eich
This skill helps you write JavaScript with deep language fundamentals, emphasizing first-class functions, prototypes, and dynamic typing for powerful, flexible
npx playbooks add skill copyleftdev/sk1llz --skill eichReview the files below or copy the command above to add this skill to your agents.
---
name: eich-language-fundamentals
description: Write JavaScript code with deep understanding of the language fundamentals as envisioned by Brendan Eich, creator of JavaScript. Emphasizes first-class functions, prototypes, and the dynamic nature of the language. Use when leveraging JavaScript's unique characteristics.
---
# Brendan Eich Style Guide
## Overview
Brendan Eich created JavaScript in 10 days at Netscape in 1995. Despite time constraints, he embedded powerful concepts: first-class functions, prototypal inheritance, and dynamic typing. Understanding his design choices unlocks JavaScript's true power.
## Core Philosophy
> "Always bet on JavaScript."
> "JavaScript has first-class functions and closures. That's a big deal."
Eich designed JavaScript to be accessible yet powerful, borrowing from Scheme (functions), Self (prototypes), and Java (syntax).
## Design Principles
1. **First-Class Functions**: Functions are values—pass them, return them, store them.
2. **Prototypal Inheritance**: Objects inherit directly from objects, not classes.
3. **Dynamic Nature**: Types are fluid; embrace duck typing.
4. **Flexibility**: The language adapts to many paradigms.
## When Writing Code
### Always
- Leverage closures for encapsulation
- Use functions as first-class citizens
- Understand the prototype chain
- Embrace JavaScript's multi-paradigm nature
- Know that objects are just property bags
### Never
- Fight the language's dynamic nature
- Ignore `undefined` and `null` semantics
- Assume JavaScript is "Java-like"
- Overlook the power of functions
### Prefer
- Function expressions and closures
- Object literals for simple objects
- Prototype delegation over deep hierarchies
- Dynamic features when they simplify code
## Code Patterns
### First-Class Functions
```javascript
// Functions as values
const greet = function(name) {
return 'Hello, ' + name;
};
// Functions as arguments
function map(array, transform) {
const result = [];
for (let i = 0; i < array.length; i++) {
result.push(transform(array[i]));
}
return result;
}
const doubled = map([1, 2, 3], function(x) { return x * 2; });
// Functions returning functions
function multiplier(factor) {
return function(number) {
return number * factor;
};
}
const double = multiplier(2);
const triple = multiplier(3);
double(5); // 10
triple(5); // 15
```
### Closures
```javascript
// Closures capture their lexical environment
function createCounter() {
let count = 0; // Private state
return {
increment: function() { return ++count; },
decrement: function() { return --count; },
value: function() { return count; }
};
}
const counter = createCounter();
counter.increment(); // 1
counter.increment(); // 2
counter.value(); // 2
// count is not directly accessible
```
### Prototypal Inheritance
```javascript
// Objects inherit from objects
const animal = {
speak: function() {
return this.sound;
}
};
const dog = Object.create(animal);
dog.sound = 'Woof!';
dog.speak(); // 'Woof!'
const cat = Object.create(animal);
cat.sound = 'Meow!';
cat.speak(); // 'Meow!'
// The prototype chain
dog.hasOwnProperty('sound'); // true
dog.hasOwnProperty('speak'); // false (inherited)
```
### Dynamic Objects
```javascript
// Objects are dynamic property bags
const obj = {};
// Add properties anytime
obj.name = 'Dynamic';
obj['computed-key'] = 'Works too';
// Delete properties
delete obj.name;
// Check existence
'computed-key' in obj; // true
// Iterate properties
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
console.log(key, obj[key]);
}
}
```
## Mental Model
Eich's JavaScript is built on:
1. **Functions are fundamental** — Not just procedures, but values
2. **Objects are flexible** — Dynamic bags of properties
3. **Prototypes link objects** — Delegation, not copying
4. **Closures preserve scope** — Functions remember their birth environment
## Signature Moves
- Closures for private state
- Higher-order functions for abstraction
- Prototype chain for shared behavior
- Object literals for quick structures
- Dynamic property access when needed
This skill encodes Brendan Eich’s JavaScript fundamentals: first-class functions, prototypal inheritance, closures, and the language’s dynamic nature. It guides you to write idiomatic, flexible JavaScript that leverages functions as values, object delegation, and concise patterns for pragmatic code. Use it to favor JavaScript’s strengths rather than forcing class-based or static paradigms.
The skill inspects code intent and suggests patterns that align with Eich’s vision: using function expressions, closures for private state, Object.create and prototype delegation, and object literals for quick structures. It identifies places to replace class-heavy designs with prototype delegation, converts imperative loops into higher-order function usage when helpful, and highlights pitfalls around null/undefined and dynamic property access.
Why prefer prototypes over classes?
Prototypes express delegation directly and match JavaScript’s original model; they are lighter for shared behavior and avoid copying semantics implied by classical inheritance.
When should I use closures instead of properties?
Use closures when you need true private state not accessible from outside. Use properties when external access or serialization is required.
How do I avoid null/undefined errors?
Be explicit: use strict checks, default parameters, and guard patterns (e.g., obj && obj.prop) or optional chaining to handle missing values safely.