Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog. You can find information on programming, linux, documentation, tips for code and database optimization, my thoughts and rants, and whatever else I feel like sharing. Feel free to contribute to the blog by posting comments and asking questions.
JavaScript and Ajax

writing classes in javascript using mootools

This is actually really simple and gives you some nice OOP functionality a web developer would not normally have in their web applications.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var Customer = new Class({
	initialize: function(firstName, lastName, address, address2, city, state, zip, phone, email){
		this.firstName = firstName;
		this.lastName = lastName;
		this.address = address;
		this.address2 = address2;
		this.city = city;
		this.state = state;
		this.zip = zip;
		this.phone = phone;
		this.email = email;
	},
	quickSet: function(){
		this.firstName = $('firstName').value;
		this.lastName = $('lastName').value;
		this.address = $('address').value;
		this.address2 = $('address2').value;
		this.city = $('city').value;
		this.state = $('state').value;
		this.zip = $('zip').value;
		this.phone = $('ph1').value+$('ph2').value+$('ph3').value;
		this.email = $('email').value;
	}
});

In this example initialize is the constructor, which is required for a mootools class, where quickSet is a method I created for this class.

Related posts:

  1. ajax and the xmlhttprequest object
  2. sorting a multidimensional array in php
  3. slick interfaces with javascript + MooTools + mochaUI
  4. a dynamic javascript calendar that works with mootools mocha ui
  5. WaitForExit method, running command line args in c#, and other hacks

Leave a Reply