Description

Create a model

Usage

Parameters

  • name {String}

    Class name

  • name {Array} optional

    (optional) Name of the methods that can be called by the client

  • model {Object} optional

    (optional) Properties and methods of this class

Returns

Class

Example

Module in "/mods/myclass.js" :

 var CE = require("canvasengine").listen(),
    Class = CE.Class;

CE.Model.create("Player", ["start"], {

    initialize: function(user_id, username) {

    },

    start: function() {

    }

});

exports.New = function(socket, user_id, username) {
   return CE.Model.new("Player", [user_id, username], socket);
};

In main JS file :

var CE = require("canvasengine").listen(8333),
    Class = CE.Class;

CE.Model.init("Main", {

  initialize: function(socket) {
     var player = require("./player").New(1, "Foo", socket);
  }

});

Discussion