<commit_before>---
layout: default
---
# Welcome to CanJS!

CanJS is an MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.  It provides:

 - __can.Construct__  - inheritable constructor functions
 - __can.Control__ - declaritive event bindings
 - __can.Model__ - connect data to a RESTful JSON interface
 - __can.Observe__ - key-value binding
 - __can.route__ - backbutton and bookmarking support
 - __can.view__ - dynamic live binding client side templates
 

## Get Canned

CanJS supports jQuery, Zepto, Dojo, YUI and Mootools.  Select your download 
for the library you are using:

 - can.jquery.js (8k)
 - can.zepto.js (9k)
 - can.dojo.js (9k)
 - can.mootools.js (9k)
 - can.yui.js (9k)

This page walks through the basics of CanJS by building a 
small todo app with CanJS and jQuery.  The [Use with other libraries] section details 
the minor differencs between use with other libraries.

## can.Construct `can.Construct([classProps,] [prototypeProps])`

Constructor function made with [can.Construct](http://donejs.com/docs.html#!can.Construct) are used to create
objects with shared properties. It's used by both __can.Control__ and __can.Model__.

To create a constructor function of your own, call __can.Construct__ with the:

- __classProperties__ that are attached directly to the constructor, and
- instance __prototypeProperties__.

__can.Construct__ sets up the prototype chain so subclasses can be further 
extended and sub-classed as far as you like:


{% highlight javascript %}	
var Todo = can.Construct({
  init : function(){},
	
  author : function(){ ... },
	
  coordinates : function(){ ... },
	
  allowedToEdit: function(account) { 
    return true;
  }
});
	
var PrivateTodo = Todo({
  allowedToEdit: function(account) {
    return account.owns(this);
  }
});
{% endhighlight %}

If only one set of properties is passed to __can.Construct__, it's assumed to 
be the prototype properties.

### init `new can.Construct(arg1, arg2)`

When a constructor is called with the `new` keyword, __can.Construct__ creates the instance and 
calls [can.Construct.prototype.init](http://javascriptmvc.com/docs.html#!can.Construct.prototype.init) with 
the arguments passed to `new Constructor(...)`.

{% highlight javascript %}	
var Todo = can.Construct({
  init : function(text) {
    this.text = text
  },
  read : function(){
    console.log(this.text);
  }<commit_msg>Update index.md<commit_after>---
layout: default
---
# Welcome to CanJS!

CanJS is an MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.  It provides:

 - __can.Construct__  - inheritable constructor functions
 - __can.Control__ - declaritive event bindings
 - __can.Model__ - connect data to a RESTful JSON interface
 - __can.Observe__ - key-value binding
 - __can.route__ - backbutton and bookmarking support
 - __can.view__ - dynamic live binding client side templates
 

## Get Canned

CanJS supports jQuery, Zepto, Dojo, YUI and Mootools.  Select your download 
for the library you are using:

 - can.jquery.js (8k)
 - can.zepto.js (9k)
 - can.dojo.js (9k)
 - can.mootools.js (9k)
 - can.yui.js (9k)

This page walks through the basics of CanJS by building a 
small todo app with CanJS and jQuery.  The [Use with other libraries] section details 
the minor differencs between use with other libraries.

## can.Construct `can.Construct([classProps,] [prototypeProps])`

Constructor function made with [can.Construct](http://donejs.com/docs.html#!can.Construct) are used to create
objects with shared properties. It's used by both __can.Control__ and __can.Model__.

To create a constructor function of your own, call __can.Construct__ with the:

- __classProperties__ that are attached directly to the constructor, and
- instance __prototypeProperties__.

__can.Construct__ sets up the prototype chain so subclasses can be further 
extended and sub-classed as far as you like:


{% highlight javascript %}	
var Todo = can.Construct({
  init : function(){},
	
  author : function(){ ... },
	
  coordinates : function(){ ... },
	
  allowedToEdit: function(account) { 
    return true;
  }
});
	
var PrivateTodo = Todo({
  allowedToEdit: function(account) {
    return account.owns(this);
  }
});
{% endhighlight %}

If only one set of properties is passed to __can.Construct__, it's assumed to 
be the prototype properties.

### init `new can.Construct(arg1, arg2)`

When a constructor is called with the `new` keyword, __can.Construct__ creates the instance and 
calls [can.Construct.prototype.init](donejs.com/docs.html#!can.Construct.prototype.init) with 
the arguments passed to `new Constructor(...)`.

{% highlight javascript %}	
var Todo = can.Construct({
  init : function(text) {
    this.text = text
  },
  read : function(){
    console.log(this.text);
  }
{'fraction_non_alphanumeric': 0.10041322314049586, 'fraction_numerical': 0.002892561983471074, 'mean_word_length': 3.8751258811681772, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '992743', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1399, 'n_words': 519}