Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- };
- }());
Add Comment
Please, Sign In to add comment