/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var MYNAMESPACE = YAHOO.namespace("mynamespace"); //CLASS: MYNAMESPACE.MyClass (function() { // private var that = null; var priv1 = "123"; var priv2 = "ABC"; var privMethod = function () { priv1 += "_priv"; }; // constructor MYNAMESPACE.MyClass = function(par1, par2){ that = this; priv1 += par1; priv2 += par2; privMethod(); this.prop1 += par1; }; // public MYNAMESPACE.MyClass.prototype = { // events onClassReady : new YAHOO.util.CustomEvent("onClassReady"), onPubMethod1Loaded : new YAHOO.util.CustomEvent("onPubMethod1Loaded"), // properties prop1 : "Test1", prop2 : "999", // methods pubMethod1: function(p1){ this.onPubMethod1Loaded.fire(this.prop1, this.prop2); return this.prop1 + priv1 + p1; }, pubMethod2: function(p1){ } } // static MYNAMESPACE.MyClass.statMethod = function () { YAHOO.log(this); } })(); MYNAMESPACE.MyClass.statMethod(); // function () var myObject = new MYNAMESPACE.MyClass("_kkk", "_ppp"); myObject.onPubMethod1Loaded.subscribe(function (type, args, me) { YAHOO.log(this); // window YAHOO.log(type); // onPubMethod1Loaded YAHOO.log(args); // ["Test1_kkk", "999"] YAHOO.log(me); // Object }, myObject); YAHOO.log(myObject.prop1); YAHOO.log(myObject.pubMethod1("ioioi"));