--- title: JavaScript Tips slug: Mozilla/JavaScript_Tips translation_of: Mozilla/JavaScript_Tips ---

XUL Tips

var UniqueName = {
  _privateMember: 3,
  publicMember: "A string",

  init: function() {
    this.doSomething(this.anotherMember);
  },

  doSomething: function(aParam) {
    alert(aParam);
  }
};

XPConnect

if (target instanceof Components.interfaces.nsIRDFResource)
  return target.Value;
if (target instanceof Components.interfaces.nsIRDFLiteral)
  return target.Value;
return null;
var weakObserver = {
  QueryInterface: function QueryInterface(aIID) {
    if (aIID.equals(Components.interfaces.nsIObserver) ||
        aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
        aIID.equals(Components.interfaces.nsISupports))
       return this;
    throw Components.results.NS_NOINTERFACE;
  },
  observe: function observe(aSubject, aTopic, aState) {
  }
}

DOM elements

References