Friday 15 January 2010

javascript - How to pass jQuery No Conflict to an object I have placed in a namespace -


With the following I have created a namespace for my object:

  var namespace = {Register: function (_Name) {var chk = false; Var cob = ""; Var spc = _Name.split ("."); (Var i = 0; i & lt; spc.length; i ++) {if (cob! = "") {Cob + = ".";} Cob + = spc [i]; Chk = this.Exists (cob); If (! Chk) {this.Create (cob);}} if (chk) {"Namespace:" + _Name + "is already defined."; }}, Create: function (_Src) {eval ("window." + _Src + "= new object ();"); }, Present: function (_Src) {eval (try "{var =" false "}; {{= False;} "); Return NE; }}   

Define the object:

  Namespace. Registrar ("System.Classes.HelloWorld"); System.Classes.HelloWorld = Function (AA) {Return: Message: "Hello World!", Hello: Function (A, B) {Alert (this message + A + B); I can not apply a code in NoConflict to JQuery in the above code.  

This code wraps jQuery notefix and allows a dollar sign which I would like to repeat:

  (task (skillet, $, undefined)} {// Private property is: hahat = true; // public property skillet.English = "bacon strips"; // public methyl skillet.free = function () {var olive oil; "add" ("\ t \ n butter \ n \ t") ; AddItem (oliveOil); console.log ("frying" + skillet.needient);}; // personal method function addItem (item) {if (item! == Additional Defined) {Console.log ("add" + $ .trim (item))}}}} (window.skillet = window.skillet || {}, jquery));    

You would like to try this pattern:

  Var namespace = (function ($) {// private member var register = function (_Name) {// ...}; var create = function (_Src) {// ...}; var exists = function (_Src ) {// ...}; // Reveal that the public member is back (register: register, create: create, exists: present);}}) ();   

This does not only allow the definition of private members of all types, but rather to fulfill the internal function call with namespace or Avoids the requirement. <. / Code>.

No comments:

Post a Comment