pO

…push object function / jQuery object builder

Aims

Builder

  • Provide a standard method for creating stateful sub-plugins
  • Reduce the lines of code dramatically
  • Minimise the scope for errors
  • Generate convenient shorthands for jQuery options
  • Embedded logging and code generation

Current code

pO(name, variables, options, main, inner)

Parameter Required Type Comment
name yes String in lower case
internal variables no JSON set to 0 if absent
jQuery options no JSON set to 0 if absent
main function yes anonymous function usually calls inner functions
inner functions no JSON name + anonymous function

Steering type of sub-plugin

  • If $this is in main function arguments list -> $.fn.myname()
  • If $this is not in main function arguments list -> $.myname()

Inner functions

A JSON comprised of two fields for each record:

  • Name of the function -> an underscore is prepended automatically
  • Anonymous function – function body

Simple example – $.log() sub-plugin

  • Without internal variables or inner functions
  • See also logging section
  • Defined in here
pO("log", 0, { verbosity: 0 }, function(m, v){
    if(v) verbosity = v;
    if(verbosity && m && lvl < verbosity && console) 
        console.log(m);
});

Copyright 2005-2017, 4nf.org. All rights reserved.
Latest update: 9. February 2017