Giter Site home page Giter Site logo

mhulse / js-patterns Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 10 KB

Some of my favorite JavaScript plugin design patterns: The Facade Pattern, The Revealing Module Pattern, Immediately-invoked Function Expressions (IIFE)s, The Module Pattern imports and exports …

javascript patterns templates starting-points examples plugins jquery prototype iife modules

js-patterns's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

gtechsltn

js-patterns's Issues

Constructor pattern

Via @caseydedore:

var models = {
  Course: function () {
    this.id = 0;
    this.title = '';
    this.itemCode = '';
    this.type = 0;
    this.ccYear = 0;
    this.credits = 0;
    this.lessons = [];
    this.prerequisites = [];
    this.prerequisiteGroups = [];
    this.prerequisiteMaterials = [];
    this.prerequisiteOthers = [];
    this.comments = '';
    this.isCore = false;
    this.isPrint = false;
    this.getIsLocal = function () {
      return this.itemCode.indexOf('.LC') >= 0;
    };
    this.getIsApplication = function () {
      return this.type === 4;
    };
    this.isAdvanced = function () {
      return this.type !== 4 &&
        !this.getIsLocal() &&
        !this.isCore;
    };
    this.isPrint = function () {
      return this.type !== 2;
    };
    this.application = {
      id: '',
      title: '',
      number: ''
    };
  },
  Worksheet: function () {
    this.id = 0;
    this.comments = '';
    this.title = '';
    this.type = 'roadmap';
    this.author = '';
    this.tooltips = [];
    this.trackDefaults = '';
    this.ccID = '';
    this.comment = '';
    this.lastUpdated = '';
    this.createDate = '';
    this.programId = 0;
    this.curriculumStartDate = '';
    this.clcsSelectable = 0;
    this.programDefault = 0;
    this.sortOrder = 0;
    this.getWorksheetType = function() {
      if (uiConfig.adminMode.getIsAdmin()) {
        return $('input[type=radio][name=worksheet_type]:checked').val();
      } else if ($defaultViewSelector.find('option:selected').attr('data-snapshot') == '1' ||
        $('#radio_snapshot').prop('checked')) {
        return 'snapshot';
      }
      return this.type;
    };
  }
};
// var course = new models.Course();
// var worksheet = new models.Worksheet();

http://www.samselikoff.com/blog/some-Javascript-constructor-patterns/

'nother … AMD/Node/CommonJS/Browser boilerplate pattern

(function( factory ){
    if ( typeof define === 'function' && define.amd ) {
        // AMD
        define( ['jquery', 'datatables', 'datatables-editor'], factory );
    }
    else if ( typeof exports === 'object' ) {
        // Node / CommonJS
        module.exports = function ($, dt) {
            if ( ! $ ) { $ = require('jquery'); }
            factory( $, dt || $.fn.dataTable || require('datatables') );
        };
    }
    else if ( jQuery ) {
        // Browser standard
        factory( jQuery, jQuery.fn.dataTable );
    }
}(function( $, DataTable ) {
'use strict';
 
 


var
 
    create: function ( conf ) {
    },
 
    get: function ( conf ) {
    
    },
 
    set: function ( conf, val ) {
    },
 
    enable: function ( conf ) {
    },
 
    disable: function ( conf ) {
    },
 
    inst: function ( conf ) {
    },
    update: function ( conf, data ) {
    },
 
    focus: function ( conf ) {
    }
};
 
 
}));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.