Skip to content
Javascript class library
JavaScript HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build
src
test
.bowerrc
.editorconfig
.gitattributes
.gitignore
.jshintrc
Gruntfile.js
LICENSE.md
README.md
bower.json
package.json

README.md

js-tmclasses

A simple javascript class library. More features will be added in the future. This project is not documented yet, but I have simple usage examples to get started.

Usage

This library has been built using require.js, so it can be loaded as an AMD module with that. I've also used almond.js to make a standalone build that can be loaded as a regular script and used as a global variable.

Require/AMD

Download the whole repo or just the src directory and put it somewhere require has access to. Configure the path to the src directory in require.js:

requirejs.config({
	paths: {
		tmclasses: 'vendor/js-tmclasses/src'
	}
});

Require tmclasses/tmclasses and then use the create method to create a class. An example:

var tmclasses = require('tmclasses/tmclasses');

var MyClass = tmclasses.create({
	init: function(_opts){
		console.log('MyClass instantiated with options ', _opts);
		this.__parent(arguments);
	}
	,properties: {
		foo: 'foo'
		,getFoo: function(){
			return this.foo;
		}
		,setFoo: function(_newFoo){
			this.foo = _newFoo;
			return this;
		}
	}
});

var myInstance = new MyClass({option1: 'value1', option2: 'value2'});

Standalone build

Download the whole repo and run grunt requirejs:almond in the repo root. Then move 'dist/tmclasses.almond.js' into your project or reference it in place.

<script src="/js-tmclasses/dist/tmclasses.almond.js"></script>

In your own script, you can access and use it much like the AMD example, without the need to require anything.

var MyClass = tmclasses.create({
	init: function(_opts){
		console.log('MyClass instantiated with options ', _opts);
		this.__parent(arguments);
	}
	,properties: {
		foo: 'foo'
		,getFoo: function(){
			return this.foo;
		}
		,setFoo: function(_newFoo){
			this.foo = _newFoo;
			return this;
		}
	}
});
You can’t perform that action at this time.