Guest User

Untitled

a guest
Feb 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. Object.extend(NativeObject.prototype, function() {
  2. // PDoc main documentation goes first, followed by normal implementation.
  3.  
  4. /**
  5. * NativeObject#computeSomething()
  6. * This methods definitely computes something.
  7. **/
  8. function computeSomething() {
  9. // The method, the normal way
  10. }
  11.  
  12. // Then come implementations, with optional technical documentation.
  13. // This is imaginary PDoc markup...
  14.  
  15. /** implementation of: NativeObject#computeSomething
  16. * computeSomethingWithAwesomeCapability
  17. * Uses awesome when available, making it N times faster.
  18. **/
  19. function computeSomethingWithAwesomeCapability() {
  20. // The method using awesome vendor feature
  21. }
  22.  
  23. /** ie, implementation of: NativeObject#computeSomething
  24. * computeSomethingFixingAwfulBug
  25. * Fixes #12345.
  26. **/
  27. function computeSomethingFixingNastyBug() {
  28. // The method fixing yet another bug
  29. }
  30.  
  31. // Then come tests
  32.  
  33. function computeSomethingShouldFixNastyBug() {
  34. // complex tests are wrapped in functions
  35. }
  36.  
  37. // Then come branching
  38.  
  39. if (computeSomethingShouldFixNastyBug()) {
  40. computeSomething = computeSomethingFixingNastyBug;
  41. } else if ('awesomeCapability' in navigator) { // trivial tests are inline
  42. computeSomething = computeSomethingWithAwesomeCapability;
  43. }
  44.  
  45. // For missing methods on some browsers (say `concat` on `Array`)
  46.  
  47. function concat() {
  48. // concat implementation
  49. }
  50.  
  51. if ('concat' in NativeObject.prototype) {
  52. concat = NativeObject.prototype.concat;
  53. }
  54.  
  55. return {
  56. // all these lines are consistently "identifier: identifier";
  57. computeSomething: computeSomething,
  58. concat: concat
  59. };
  60. }());
Add Comment
Please, Sign In to add comment