JavaScript/Notes/CustomEvents: Difference between revisions

From Noisebridge
Jump to navigation Jump to search
Garrett (talk | contribs)
Created page with "== Under Construction == An event is a function call that signifies something happened. <source language="javascript"> var TableSort = (function() { function TableSort(id) ..."
 
Garrett (talk | contribs)
Line 2: Line 2:
An event is a function call that signifies something happened.
An event is a function call that signifies something happened.


<source language="javascript">
<source lang="javascript">
var TableSort = (function() {
var TableSort = new Factory(function() {


function TableSort(id) {
  this.id = id;
}


TableSort.prototype = {
  function _getSortFunction(sortType) {
  sortBy : function(sortType) {
    if(sortType == "number") {
    if(!sortedBy
    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);
      }
    },
    onsort : Function.prototype
   }
   }
}


return { getById
  return TableSort;
})();
})();
</source>
</source>
The <code>Factory</code> is explained in [https://noisebridge.net/index.php?title=JavaScript/Notes/Factory Factory] lesson.

Revision as of 15:07, 6 January 2014

Under Construction

An event is a function call that signifies something happened.

<source lang="javascript"> var TableSort = new 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);
     }
   },

   onsort : Function.prototype
 }
 return TableSort;

})(); </source> The Factory is explained in Factory lesson.