JavaScript/Notes/CustomEvents: Difference between revisions
Jump to navigation
Jump to search
Line 5: | Line 5: | ||
<source lang="javascript"> | <source lang="javascript"> | ||
Factory(function() { | |||
function _getSortFunction(sortType) { | function _getSortFunction(sortType) { | ||
if(sortType == "number") { | if(sortType == "number") { | ||
return function() { } | return function() { }; | ||
} | } | ||
} | } | ||
function _isSortedBy(tableSort, sortType) { | function _isSortedBy(tableSort, sortType) { | ||
} | } | ||
var configData = {}; | var configData = {}; | ||
function TableSort(id, config) { | function TableSort(id, config) { | ||
this.id = id; | this.id = id; | ||
configData[id] = Object.create(config); | configData[id] = Object.create(config); | ||
} | } | ||
TableSort.prototype.sortBy = function(sortType) { | TableSort.prototype.sortBy = function(sortType) { | ||
var config = configData[this.id]; | var config = configData[this.id]; | ||
if( | if(config.currentSort != sortType) { | ||
config.sortFunction(this); | config.sortFunction(this); | ||
this.onsort(sortType); | this.onsort(sortType); | ||
} | } | ||
}; | }; | ||
return TableSort; | return TableSort; | ||
}); | }); | ||
</source> | </source> |
Revision as of 08:41, 11 January 2014
Under Construction
An event is a function call that signifies something happened.
Custom events are functions that you call to notify subscribers. The function is either defined by the "class" (default) or shadowed on the instance, by the client of the API.
<source lang="javascript">
Factory(function() { function _getSortFunction(sortType) { if(sortType == "number") { return function() { }; } } function _isSortedBy(tableSort, sortType) { } var configData = {}; function TableSort(id, config) { this.id = id; configData[id] = Object.create(config); } TableSort.prototype.sortBy = function(sortType) { var config = configData[this.id]; if(config.currentSort != sortType) { config.sortFunction(this); this.onsort(sortType); } }; return TableSort;
}); </source>