pls help w/unusual code.. (YUI/JSON)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • maya

    pls help w/unusual code.. (YUI/JSON)


    (function() {
    function initProductImag ePanels() {
    var elements = YAHOO.util.Dom. getElementsByCl assName('produc tImage',
    'img');

    for(var i = 0; i < elements.length ; i++) {

    var el = new YAHOO.util.Elem ent(elements[i]);

    var fnCallback = function(e, obj) {
    var productImagePan el = new
    YAHOO.com.mydom ain.widget.Prod uctImagePanel(o bj.get('name')) ;
    productImagePan el.initWithSkuC ode(obj.get('na me'));
    };

    YAHOO.util.Even t.addListener(e lements[i], "click", fnCallback, el);
    }
    }

    YAHOO.util.Even t.addListener(w indow, "load", initProductImag ePanels);
    })();


    ---------------------

    at work we're starting to use yahoo's YUI framework
    (http://developer.yahoo.com/yui/) now I know Javascript fairly well, but
    now we're doing this in conjunction with JSON.. we're using code like
    above... I'm not familiar with this kind of syntax.. (a function
    declared inside parens, etc..) are there any tutorials out there for
    this kind of JavaScript syntax?
    and this is nothing, am working also with this one,
    http://www.mayacove.com/js/div.js.. and SOMEWHERE in this code is
    something that is causing a weird error in IE, namely:

    unexpected call to method or property access

    (no erros in FF..)

    and since I'm not familiar with this kind of code (was written by
    someone else where I work) I'm having a hard time debugging it.. I would
    like not just to solve this problem but in general to learn syntax of
    this new kind of code from the ground up... would like to find
    tutorials, etc.. where I can familiarize myself w/this syntax..

    thank you very much...






  • maya

    #2
    Re: pls help w/unusual code.. (YUI/JSON)

    maya wrote:
    >
    (function() {
    function initProductImag ePanels() {
    var elements =
    YAHOO.util.Dom. getElementsByCl assName('produc tImage', 'img');
    >
    for(var i = 0; i < elements.length ; i++) {
    >
    var el = new YAHOO.util.Elem ent(elements[i]);
    >
    var fnCallback = function(e, obj) {
    var productImagePan el = new
    YAHOO.com.mydom ain.widget.Prod uctImagePanel(o bj.get('name')) ;
    productImagePan el.initWithSkuC ode(obj.get('na me'));
    };
    >
    YAHOO.util.Even t.addListener(e lements[i], "click",
    fnCallback, el);
    }
    }
    >
    YAHOO.util.Even t.addListener(w indow, "load", initProductImag ePanels);
    })();
    >
    >
    ---------------------
    >
    at work we're starting to use yahoo's YUI framework
    (http://developer.yahoo.com/yui/) now I know Javascript fairly well, but
    now we're doing this in conjunction with JSON.. we're using code like
    above... I'm not familiar with this kind of syntax.. (a function
    declared inside parens, etc..) are there any tutorials out there for
    this kind of JavaScript syntax?
    and this is nothing, am working also with this one,
    http://www.mayacove.com/js/div.js.. and SOMEWHERE in this code is
    something that is causing a weird error in IE, namely:
    >
    unexpected call to method or property access
    >
    (no erros in FF..)
    >
    and since I'm not familiar with this kind of code (was written by
    someone else where I work) I'm having a hard time debugging it.. I would
    like not just to solve this problem but in general to learn syntax of
    this new kind of code from the ground up... would like to find
    tutorials, etc.. where I can familiarize myself w/this syntax..
    >
    thank you very much...
    >
    and also, I would like to know, in general, what is purpose of JSON..
    why declare objets (arrays) like it says here, http://www.json.org/ and
    not in usual way? what would be advantage of using JSON instead of
    using normal JavaScript arrays??

    thank you..

    Comment

    • Jorge

      #3
      Re: pls help w/unusual code.. (YUI/JSON)

      On Nov 3, 3:27 pm, maya <maya778...@yah oo.comwrote:
      (...)
      at work we're starting to use yahoo's YUI framework
      (http://developer.yahoo.com/yui/) now I know Javascript fairly well, but
      now we're doing this in conjunction with JSON..  we're using code like
      above...  I'm not familiar with this kind of syntax..  (a function
      declared inside parens, etc..)  are there any tutorials out there for
      this kind of JavaScript syntax?
      (...)
      (function () { /*code*/ })();

      This just means "compile and run this function now, inmediatly". It's
      similar to:

      function foo () { /*code*/ }
      foo();

      With the added benefit of not using a symbol name because it's invoked
      "from the declaration itself", so there's no need to reference it
      after the declaration: the idea is:

      (function)(); -declare the function and execute it inmediatly

      versus

      var= function; -declare the function
      var(); -execute it

      HTH,
      --
      Jorge.

      Comment

      • Jorge

        #4
        Re: pls help w/unusual code.. (YUI/JSON)

        On Nov 3, 3:46 pm, maya <maya778...@yah oo.comwrote:
        >
        and also, I would like to know, in general, what is purpose of JSON..
        why declare objets (arrays) like it says here,http://www.json.org/and
        not in usual way?  what would be advantage of using JSON instead of
        using normal JavaScript arrays??
        >
        The "advantage" of JSON is that it's able to express data structures
        of almost any complexity as a simple string of text. Text can be very
        easily sent over the network, and the original data structures are
        super-easily recomposed with a quick and simple eval(text) at the
        receiving end.

        --
        Jorge.

        Comment

        • maya

          #5
          Re: pls help w/unusual code.. (YUI/JSON)

          Jorge wrote:
          On Nov 3, 3:27 pm, maya <maya778...@yah oo.comwrote:
          >(...)
          >at work we're starting to use yahoo's YUI framework
          >(http://developer.yahoo.com/yui/) now I know Javascript fairly well, but
          >now we're doing this in conjunction with JSON.. we're using code like
          >above... I'm not familiar with this kind of syntax.. (a function
          >declared inside parens, etc..) are there any tutorials out there for
          >this kind of JavaScript syntax?
          >(...)
          >
          (function () { /*code*/ })();
          >
          This just means "compile and run this function now, inmediatly". It's
          similar to:
          >
          function foo () { /*code*/ }
          foo();
          >
          With the added benefit of not using a symbol name because it's invoked
          "from the declaration itself", so there's no need to reference it
          after the declaration: the idea is:
          >
          (function)(); -declare the function and execute it inmediatly
          >
          versus
          >
          var= function; -declare the function
          var(); -execute it
          >
          HTH,
          --
          Jorge.

          thank you.. why is the function declared inside ()?? and why is there
          an extra set of () after the function????

          thank you..

          Comment

          • maya

            #6
            Re: pls help w/unusual code.. (YUI/JSON)

            Jorge wrote:
            On Nov 3, 3:46 pm, maya <maya778...@yah oo.comwrote:
            >and also, I would like to know, in general, what is purpose of JSON..
            >why declare objets (arrays) like it says here,http://www.json.org/and
            >not in usual way? what would be advantage of using JSON instead of
            >using normal JavaScript arrays??
            >>
            >
            The "advantage" of JSON is that it's able to express data structures
            of almost any complexity as a simple string of text. Text can be very
            easily sent over the network, and the original data structures are
            super-easily recomposed with a quick and simple eval(text) at the
            receiving end.
            >
            --
            Jorge.
            thank you so much Jorge..

            so what is diff betw declaring a function thus:

            (function() {

            and thus:

            Yns.ProductImag e = function (imageName, oConfigs) {


            am struggling a lot trying to understand this... (Jorge, just visited
            yr site, it looks interesting (got any JSON tutorials in there?)
            yo soy chilena...:)


            Comment

            Working...