带有自定义命名空间的jQuery应用程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有自定义命名空间的jQuery应用程序相关的知识,希望对你有一定的参考价值。
/* inspired by iNettus tutorial http://net.tutsplus.com/tutorials/javascript-ajax/inettuts/ */ var JqAppName = { jQuery: $, settings: { defaults:{}, individual:{ elemId1: {}, elemId2: {} } }, init: function(){ this.method1(); this.method2(); this.method3(); }, getElemSettings: function(arg){ // pass in either an element ID or an object literal containing options to override settings.default var $ = this.jQuery, settings = this.settings; if ( typeof(arg) === "undefined" ) { return settings.defaults; } else if ( typeof(arg) === "string" ) { return (arg&&settings.individuals[arg]) ? $.extend({}, settings.defaults, settings.individuals[arg]) : settings.defaults; } else if ( typeof(arg) === "object" ) { return $.extend({}, settings.defaults, args ); } }, method1: function(){ var JqAppName = this, $ = this.jQuery, settings = this.settings; // do something simple without messing with individual settings } method2: function(id){ // pass in an element id to get its pre-set from settings.individual.elemIdX var JqAppName = this, $ = this.jQuery, settings = this.settings; var thisElemSettings = typeof(id) === 'undefined' ? JqAppName.getElemSettings('elemId1') : JqAppName.getElemSettings(id); // do something awesome }, method3: function(options){ // pass an an object for options to override settings.default var JqAppName = this, $ = this.jQuery, settings = this.settings; var thisElemSettings = typeof(options) === 'undefined' ? JqAppName.getElemSettings({/* options hash */}) : JqAppName.getElemSettings(options); // do something awesomer } } // end of JqApp scope
以上是关于带有自定义命名空间的jQuery应用程序的主要内容,如果未能解决你的问题,请参考以下文章
C ++在boost python中使用带有命名空间的自定义智能指针