Skip to content

Instantly share code, notes, and snippets.

@samleb
Forked from savetheclocktower/gist:24571
Created November 16, 2008 06:48
Show Gist options
  • Save samleb/25421 to your computer and use it in GitHub Desktop.
Save samleb/25421 to your computer and use it in GitHub Desktop.
Object.extend(NativeObject.prototype, function() {
// PDoc main documentation goes first, followed by normal implementation.
/**
* NativeObject#computeSomething()
* This methods definitely computes something.
**/
function computeSomething() {
// The method, the normal way
}
// Then come implementations, with optional technical documentation.
// This is imaginary PDoc markup...
/** implementation of: NativeObject#computeSomething
* computeSomethingWithAwesomeCapability
* Uses awesome when available, making it N times faster.
**/
function computeSomethingWithAwesomeCapability() {
// The method using awesome vendor feature
}
/** ie, implementation of: NativeObject#computeSomething
* computeSomethingFixingAwfulBug
* Fixes #12345.
**/
function computeSomethingFixingNastyBug() {
// The method fixing yet another bug
}
// Then come tests
function computeSomethingShouldFixNastyBug() {
// complex tests are wrapped in functions
}
// Then come branching
if (computeSomethingShouldFixNastyBug()) {
computeSomething = computeSomethingFixingNastyBug;
} else if ('awesomeCapability' in navigator) { // trivial tests are inline
computeSomething = computeSomethingWithAwesomeCapability;
}
// For missing methods on some browsers (say `concat` on `Array`)
function concat() {
// concat implementation
}
if ('concat' in NativeObject.prototype) {
concat = NativeObject.prototype.concat;
}
return {
// all these lines are consistently "identifier: identifier";
computeSomething: computeSomething,
concat: concat
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment