prototype 1.0.0

  • README.md
  • Installing
  • Versions
  • 9

prototype #

version 1.0.0 build status

Prototypal inheritance for Dart.

final ProtoType Animal = new ProtoType(
    name: 'Animal',
    prototype: {#warmblooded: false},
    constructor: (ctx, [args, named]) {
      ctx
        ..clazz = args[0]
        ..species = args[1];
    });

final ProtoType Mammal = new ProtoType.extend(Animal,
    name: 'Mammal',
    prototype: {#warmblooded: true}, constructor: (ctx, [args, named]) {
  ctx.superConstructor(['Mammalia', args[0]]);
});

final ProtoType Human = new ProtoType.extend(Mammal, name: 'Human',
    constructor: (ctx, [args, named]) {
  ctx.superConstructor(['Homo sapiens']);
  ctx.name = args[0];
}, prototype: {
  #introduce: (ctx, [args, named]) {
    return 'Hi! My name is ${ctx.name}.';
  }
});

main() {
  test('human', () {
    var bob = Human.instance(['Bob']);
    expect(bob.isInstanceOf(Human), isTrue);
    expect(bob.isInstanceOf(Mammal), isTrue);
    expect(bob.isInstanceOf(Animal), isTrue);
    expect(bob.warmblooded, isTrue);
    expect(bob.clazz, equals('Mammalia'));
    expect(bob.species, equals('Homo sapiens'));
    expect(bob.name, equals('Bob'));
    bob.name = 'Tim';
    expect(bob.introduce(), equals('Hi! My name is Tim.'));
  });

  test('clone', () {
    var kingOfPop = Human.instance(['Michael Jackson']);
    var imposter = kingOfPop.clone();

    // People can mimic...
    expect(imposter.deepEquals(kingOfPop), isTrue);

    // But none can ever copy another's identity.
    expect(imposter == kingOfPop, isFalse);
  });
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  prototype: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:prototype/prototype.dart';
  
Version Uploaded Documentation Archive
1.0.0 Dec 17, 2016 Go to the documentation of prototype 1.0.0 Download prototype 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
18
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
9
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0