版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # delegates
  2. Node method and accessor delegation utilty.
  3. ## Installation
  4. ```
  5. $ npm install delegates
  6. ```
  7. ## Example
  8. ```js
  9. var delegate = require('delegates');
  10. ...
  11. delegate(proto, 'request')
  12. .method('acceptsLanguages')
  13. .method('acceptsEncodings')
  14. .method('acceptsCharsets')
  15. .method('accepts')
  16. .method('is')
  17. .access('querystring')
  18. .access('idempotent')
  19. .access('socket')
  20. .access('length')
  21. .access('query')
  22. .access('search')
  23. .access('status')
  24. .access('method')
  25. .access('path')
  26. .access('body')
  27. .access('host')
  28. .access('url')
  29. .getter('subdomains')
  30. .getter('protocol')
  31. .getter('header')
  32. .getter('stale')
  33. .getter('fresh')
  34. .getter('secure')
  35. .getter('ips')
  36. .getter('ip')
  37. ```
  38. # API
  39. ## Delegate(proto, prop)
  40. Creates a delegator instance used to configure using the `prop` on the given
  41. `proto` object. (which is usually a prototype)
  42. ## Delegate#method(name)
  43. Allows the given method `name` to be accessed on the host.
  44. ## Delegate#getter(name)
  45. Creates a "getter" for the property with the given `name` on the delegated
  46. object.
  47. ## Delegate#setter(name)
  48. Creates a "setter" for the property with the given `name` on the delegated
  49. object.
  50. ## Delegate#access(name)
  51. Creates an "accessor" (ie: both getter *and* setter) for the property with the
  52. given `name` on the delegated object.
  53. ## Delegate#fluent(name)
  54. A unique type of "accessor" that works for a "fluent" API. When called as a
  55. getter, the method returns the expected value. However, if the method is called
  56. with a value, it will return itself so it can be chained. For example:
  57. ```js
  58. delegate(proto, 'request')
  59. .fluent('query')
  60. // getter
  61. var q = request.query();
  62. // setter (chainable)
  63. request
  64. .query({ a: 1 })
  65. .query({ b: 2 });
  66. ```
  67. # License
  68. MIT