name space
by jmchen
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
JavaScript
//
// reference: http://javascriptissexy.com/12-simple-yet-powerful-javascript-tips/
//
// name space
// vector.h in origami
var ORIGAMI = ORIGAMI || {};
// constructor
// no operator overloading in JavaScript
ORIGAMI.Vector = function (a, b, c) {
this.x = a || 0;
this.y = b || 0;
this.z = c || 0;
};
ORIGAMI.Vector.prototype.abs = function () {
return Math.sqrt (this.x*this.x + this.y*this.y + this.z*this.z);
};
var v = new ORIGAMI.Vector(1,2);
alert (v.abs());