-
-
Save samleb/25421 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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