xiaohongshu
xiaohongshu
crockford-good-parts
Write JavaScript code in the style of Douglas Crockford, author of "JavaScript: The Good Parts". Emphasizes using only the reliable subset of JavaScript, avoiding problematic features, and writing clear, maintainable code. Use when writing robust, quality JavaScript.
Full skill instructions
Douglas Crockford is the author of "JavaScript: The Good Parts" and creator of JSON. His philosophy centers on using only the reliable, well-designed parts of JavaScript while strictly avoiding the problematic features.
"JavaScript has some extraordinarily good parts. In JavaScript, there is a beautiful, elegant, highly expressive language that is buried under a steaming pile of good intentions and blunders."
"It is better to be clear than clever."
Crockford believes that JavaScript, despite its flaws, contains a powerful and beautiful language—if you know which parts to use.
Use the Good Parts: Stick to the reliable subset of the language.
Avoid the Bad Parts: Don't use features that are error-prone or confusing.
Clarity Over Cleverness: Code should be immediately understandable.
Lint Everything: Use tools like JSLint to enforce quality.
=== and !== (strict equality)var/let/const statement per scope (Crockford's older style)== or != (type coercion equality)eval() or Function() constructorwith statement++ or -- (prefer += 1)new for primitives (new String, new Number, new Boolean)Object.create() over constructor functionsnew Object()new Array()Array.isArray() over instanceof Array// BAD: Constructor function with new
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.greet = function () {
return 'Hello, ' + this.name;
};
var person = new Person('Alice', 30);
// GOOD: Factory function (no new required)
function createPerson(name, age) {
return {
name: name,
age: age,
greet: function () {
return 'Hello, ' + name; // Closure for privacy
}
};
}
var person = createPerson('Alice', 30);
// BETTER: Object.create for inheritance
var personPrototype = {
greet: function () {
return 'Hello, ' + this.name;
}
};
function createPerson(name, age) {
var person = Object.create(personPrototype);
person.name = name;
person.age = age;
return person;
}
// The module pattern for encapsulation
var counter = (function () {
var count = 0; // Private variable
return {
increment: function () {
count += 1;
return count;
},
decrement: function () {
count -= 1;
return count;
},
getCount: function () {
return count;
}
};
}());
counter.increment(); // 1
counter.getCount(); // 1
// count is not accessible directly
// BAD: Type coercion surprises
'' == false // true (!)
0 == '' // true (!)
null == undefined // true (!)
// GOOD: Strict equality, no surprises
'' === false // false
0 === '' // false
null === undefined // false
// Always use strict equality
if (value === null) {
// handle null
}
if (typeof value === 'undefined') {
// handle undefined
}
// BAD: Anonymous function
var numbers = [1, 2, 3];
numbers.map(function (n) {
return n * 2;
});
// GOOD: Named function (better stack traces, self-documenting)
function double(n) {
return n * 2;
}
numbers.map(double);
// BAD: Relying on hoisting
greet('Alice');
function greet(name) {
return 'Hello, ' + name;
}
// GOOD: Define before use
function greet(name) {
return 'Hello, ' + name;
}
greet('Alice');
// BAD: Constructor forms
var arr = new Array();
var obj = new Object();
var str = new String('hello');
// GOOD: Literal forms
var arr = [];
var obj = {};
var str = 'hello';
// BAD: Array constructor ambiguity
var a = new Array(3); // [undefined, undefined, undefined]
var b = new Array(1, 2); // [1, 2]
// GOOD: Always predictable
var a = [undefined, undefined, undefined];
var b = [1, 2];
// Proper try-catch usage
function parseJSON(text) {
try {
return JSON.parse(text);
} catch (e) {
console.error('Invalid JSON:', e.message);
return null;
}
}
// Throw with Error objects, not strings
// BAD:
throw 'Something went wrong';
// GOOD:
throw new Error('Something went wrong');
eval(): Security risk, performance killerwith: Ambiguous scope, deprecated== and !=: Type coercion causes bugs++ and --: Encourage trickeryvoid: Confusing and unnecessarynew String(), new Number(), new Boolean()arguments: Use rest parameters insteadCrockford approaches JavaScript by asking:
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience