MyNamespace.MyClass.registerClass('MyNamespace.MyClass', Sys.IComponent);
MyNamespace.MyClass.registerClass('MyNamespace.MyClass', null, Sys.IDisposable);
MyNamespace.MyClass.callBaseMethod(this, 'dispose');
dispose: function dispose() { $clearHandlers(this.get_element()); this._buttonReference.removeHandler('click', this._clickHandler); window.clearInterval(this._tick); MyNamespace.MyClass.callBaseMethod(this, 'dispose'); }
this._events = null;
delete this._events;
MyNamespace.MyClass = function MyClass () { this._interval = 1000; this._enabled; this._timer = null; this._tick = function() { alert('Ticked...'); } }
MyClass = function MyClass() { this._tick = function() { alert('tick'); }; } var a = new MyClass(); var b = new MyClass();// functions are not the same alert(a._tick === b._tick);MyClass2 = function MyClass2() { }; MyClass2.prototype = { _tick : function tick() { alert('tick'); } } var c = new MyClass2(); var d = new MyClass2();// functions are the same alert(c._tick === d._tick);
MyNamespace.MyClass = function MyClass () { this._interval = 1000; this._enabled; this._timer = null; }MyNamespace.MyClass.prototype = { _tick: function tick() { alert('Ticked...'); } }MyNamespace.MyClass.registerClass('MyNamespace.MyClass');
MyNamespace.MyClass.prototype = { _tick: function tick() { alert('Ticked...'); }, _tock: function tock() { alert('Tocked...'); } }
Sys.UI.Key = function Key() { }Sys.UI.Key.prototype = { backspace: 8, tab: 9, enter: 13, esc: 27, space: 32, pageUp: 33, pageDown: 34, end: 35, home: 36, left: 37, up: 38, right: 39, down: 40, del: 127 }Sys.UI.Key.registerEnum('Sys.UI.Key');
MyNameSpace.MyClass.prototype.foo = function foo(p1, p2) { // other code removed if (p2) { // use param2 parameter } // other code removed }
/// <param name="p2" type="Type" optional="true" mayBeNull="true"></param>
// call function myobject.applySettings(this, { width: 10, height: 100, color: 'red', message: 'Do not click here' });
function initialize() { Sys.UI.Behavior.callBaseMethod(this, 'initialize'); var name = this.get_name(); if (name) this._element[name] = this; }
set_text: function set_text(value) { if (this._text !== value) { this._text = value; this.raisePropertyChanged('text'); } }
MyNamespace.Sample = function Sample(error, dataItems) { // call base constructor MyNamespace.Sample.initializeBase(this); // initialize member variables not set by constructor params this._handled = false; // initialize main properties, allowing for optional params this._error = error; this._dataItems = dataItems || {}; }
function add_amountChanged(handler) { this._events.addHandler("amountChanged", handler); } function remove_amountChanged(handler) { this._events.removeHandler("amountChanged", handler); }
MyNamespace.AmountChangedEventArgs = function AmountChangedEventArgs(amount) { MyNamespace.AmountChangedEventArgs.initializeBase(this); this._amount = amount; } MyNamespace.AmountChangedEventArgs.prototype = { get_amount: function get_amount () { return this._amount; } } MyNamespace.AmountChangedEventArgs.registerClass( 'MyNamespace.AmountChangedEventArgs', Sys.EventArgs);
function _raiseAmountChanged(args) { if (!this._events) return; var handler = this._events.getHandler("amountChanged"); if (handler) { handler(this, args); } }
if (someCondition){ this._raiseAmountChanged( new MyNamespace.AmountChangedEventArgs(someParameter)); }
function add_amountChanged(handler) { Sys.Observer.addEventHandler( this, "amountChanged", handler); } function remove_amountChanged(handler) { Sys.Observer.removeEventHandler( this, "amountChanged", handler); }
dispose: function() { Sys.Observer.clearEventHandlers(this); }
function _handleAmountChanged(sender, args) { // code removed }
var handler = Function.createDelegate(this, this._handleAmountChanged); component.add_amountChanged(handler);
MyNamespace.Errors.accountClosed = function accountClosed(sourceId) { var displayMessage = "MyNamespace.AccountClosedException: " + MyNamespace.Res.accountClosed; var err = Error.create(displayMessage, { name: "MyNamespace.AccountClosedException", source: sourceId }); err.popStackFrame(); return err; }
throw MyNamespace.Errors.accountClosed(this._id);
MyNamespace.Res = { accountClosed: 'The account is already closed' }
var err = Error.create(displayMessage, { name: "MyNamespace.AccountClosedException", source: sourceId });