项目作者: writetome51

项目描述 :
An abstract Typescript/Javascript class with properties and methods that maybe every class should have
高级语言: TypeScript
项目地址: git://github.com/writetome51/typescript-base-class.git
创建时间: 2018-12-16T08:35:08Z
项目社区:https://github.com/writetome51/typescript-base-class

开源协议:MIT License

下载


BaseClass

An abstract Typescript/Javascript class with properties and methods that maybe
every class should have.

Properties

className: string (read-only)

Methods

  1. protected _createGetterAndOrSetterForEach(
  2. propertyNames: string[],
  3. configuration: IGetterSetterConfiguration
  4. ) : void
  5. /*********************
  6. Use this method when you have a bunch of properties that need getter and/or
  7. setter functions that all do the same thing. You pass in an array of string
  8. names of those properties, and the method attaches the same getter and/or
  9. setter function to each property.
  10. IGetterSetterConfiguration is this object:
  11. {
  12. get_setterFunction?: (
  13. propertyName: string, index?: number, propertyNames?: string[]
  14. ) => Function,
  15. // get_setterFunction takes the property name as first argument and
  16. // returns the setter function. The setter function must take one
  17. // parameter and return void.
  18. get_getterFunction?: (
  19. propertyName: string, index?: number, propertyNames?: string[]
  20. ) => Function
  21. // get_getterFunction takes the property name as first argument and
  22. // returns the getter function. The getter function must return something.
  23. }
  24. *********************/
  25. protected _returnThis_after(voidExpression: any) : this
  26. // voidExpression is executed, then function returns this.
  27. // Even if voidExpression returns something, the returned data isn't used.
  28. protected _errorIfPropertyHasNoValue(
  29. property: string, // can contain dot-notation, i.e., 'property.subproperty'
  30. propertyNameInError? = ''
  31. ) : void
  32. // If value of this[property] is undefined or null, it triggers fatal error:
  33. // `The property "${propertyNameInError}" has no value.`

Explanation of syntax in above code examples

Variable declaration: varName: type
Function declaration: functionName(...parameters): type_returned

When specifying a variable type must be a specific function:
varName: (...parameters) => type_returned

Optional parameter in a function:
parameterName? = (default_value) or parameterName?: type

Optional property in an object: propertyName?: type

Variable parsed inside a literal string:

  1. `This is a string containing the value of ${varName}`

Installation

npm i @writetome51/base-class

Loading

  1. import { BaseClass } from '@writetome51/base-class';

License

MIT