Skip to content

Latest commit

 

History

History
143 lines (112 loc) · 2.9 KB

types.md

File metadata and controls

143 lines (112 loc) · 2.9 KB

Types

Creation

nice.Type('Animal')
  .string('name')
  .number('weight')
  .boolean('hasTail')
  .by((z, name) => z.name(name));

const jim = nice.Animal('Jim').weight(5);
jim.name();       // Jim 
jim.weight();     // 5

// by default created type extends nice.Obj
jim.isObj()   // true

Type name should start with capital letter.

Inheritance

nice.Animal.extend('Dog')
  .string('breed')
  .by((z, name) => z.super(name).hasTail(true));
  
const buddy = nice.Dog('Buddy');

buddy.hasTail();  //true
buddy.isAnimal();  //true
buddy.isDog();  //true

Method overload

nice.Func.Animal('voice', () => console.log('Hm'));
nice.Func.Dog('voice', () => console.log('Woof'));

buddy.voice();  // 'Woof'
jim.voice();    // 'Hm'

Embedded types

Here are some of embedded types:

  • Anything
    • Something
    • Nothing
      • Error
      • Undefined
      • Null
      • Fail