Code Monkey home page Code Monkey logo

prototype_vim's Introduction

prototype leverages vimscript's |dictionary-function|s to enable 
JavaScript-like prototype-based programming.

Example: >

    " Define a prototype
    let x1 = prototype#New({'a': 2, 'b': 3})
    function! x1.Foo(a) dict "{{{3
        return "x1-". (self.a * a:a)
    endf
    echo x1.Foo(10)
    => x1-20

    " Inherit from a prototype
    let x2 = prototype#New({'a': 33}, x1)
    echo x2.Foo(10)
    => x1-330

    echo x2.b
    => 3

    " Change the prototype
    let x1a = prototype#New({'a': 20, 'b': 30, 'c': 50})
    function! x1a.Foo(a) dict "{{{3
        return "x1a-". (self.c * a:a)
    endf
    call x2.__Prototype(x1a)
    echo x2.Foo(10)
    => x1a-500

See ../spec/prototype/prototype.vim for more examples.


                                                    *prototype-objects*
Objects~

Objects are created created with the |prototype#New()| function. Strict 
objects whose validity is checked on certain operations can be created 
with |prototype#strict#New()|.

Example: >

    let o = prototype#New({'a': 1, 'b': 2})
    function! o.Foo(x) dict
        return self.a * a:x
    endf

An object has the following additional fields and method(s):

    o.__Prototype(prototype) ... Set the prototype
    o.__prototype            ... Access the prototype
    o.__Get(key, [default])  ... Get key's value, call 
                                 o.__Default(key) if defined.
    o.__Set(field, value)    ... Set an attribute and validate

For internal use:

    o.__abstract             ... The fields that define the assured 
                                 interface of the object (those 
                                 fields not inherited from prototypes)

You should not overwrite the values of these fields. As a rule, the 
names of prototype-specific methods/attributes are prefixed with two 
underscores. Any method/attribute that is prefixed with an underscore 
won't inherited by child objects.


-----------------------------------------------------------------------

Status:  Work in progress
Install: See http://github.com/tomtom/vimtlib/blob/master/INSTALL.TXT
See http://github.com/tomtom for related plugins.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.