Loading ...
Sorry, an error occurred while loading the content.

Re: [ydn-javascript] Re: YUI.namespace problem

Expand Messages
  • Satyam
    Beyond the call to YAHOO s namespace function, the rest of the code is not specific to YUI, it is a plain JavaScript trick. Here you have it more detailed:
    Message 1 of 5 , Aug 23, 2008
    • 0 Attachment
      Beyond the call to YAHOO's namespace function, the rest of the code is
      not specific to YUI, it is a plain JavaScript trick.

      Here you have it more detailed:

      http://yuiblog.com/blog/2007/06/12/module-pattern/

      Satyam


      whiteboy6969ca wrote:
      > I found the problem, but that wasn't it. Apparently you have to return
      > your methods and execute the anonymous function. This is poorly
      > documented on the YAHOO Global Object page. There are no examples of
      > this whatsoever.
      > *********** select_widget.js **************
      > YAHOO.namespace("part_manager");
      > YAHOO.part_manager.SelectWidget = function() {
      > return {
      > giveAlert: function() {
      > alert("reached giveAlert()");
      > },
      > giveAnotherAlert: function() {
      > alert("reached giveAnotherAlert()");
      > }
      > }
      > }();
      >
      > *********** my_javascript.js ****************
      > YAHOO.util.Event.onDOMReady(function () {
      > var SelectWidget = YAHOO.part_manager.SelectWidget;
      > SelectWidget.giveAlert();
      > SelectWidget.giveAnotherAlert();
      > alert("hello world");
      > });
      >
      >
      > Thanks for the suggestion though, it got me thinking if anything :)
      > --- In ydn-javascript@yahoogroups.com, "Frank Dietrich"
      > <fdietrich@...> wrote:
      > >
      > >
      > > are You missing the parenthesis?
      > >
      > > >var SelectWidget = YAHOO.part_manager.SelectWidget; // Fails here
      > >
      > > -->
      > > var SelectWidget = YAHOO.part_manager.SelectWidget();
      > >
      > >
      > >
      > > *********** REPLY SEPARATOR ***********
      > >
      > > On 22.08.08 at 14:03 whiteboy6969ca wrote:
      > >
      > > >The Javascript here just fails silently. What am I doing wrong?
      > > >
      > > >****************** my_html.html *************************
      > > ><script type="text/javascript" src="select_widget.js"></script>
      > > ><script type="text/javascript" src="my_js.js"></script>
      > > >
      > > >***************** select_widget.js **********************
      > > >YAHOO.namespace("part_manager");
      > > >YAHOO.part_manager.SelectWidget = function() {
      > > > // Select rows when they are added to a table (visual cue)
      > > > selectRows: function(ev) {
      > > > this.unselectAllRows();
      > > > for(var i=0; i<ev.records.length; i++) {
      > > > this.selectRow(ev.records[i]);
      > > > }
      > > > }
      > > >}
      > > >
      > > >***************** my_javascript.js **********************
      > > >var SelectWidget = YAHOO.part_manager.SelectWidget; // Fails here
      > > >alert("hello world"); // Doesn't get executed!
      > > >
      > > >What gives?
      > > >
      > > >
      > > >
      > > >------------------------------------
      > > >
      > > >Yahoo! Groups Links
      > > >
      > > >
      > > >
      > >
      >
      > No virus found in this incoming message.
      > Checked by AVG - http://www.avg.com
      > Version: 8.0.138 / Virus Database: 270.6.6/1625 - Release Date: 21/08/2008 6:04
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.