By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 1,962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

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

P: n/a

(function() {
function initProductImagePanels() {
var elements = YAHOO.util.Dom.getElementsByClassName('productImag e',
'img');

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

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

var fnCallback = function(e, obj) {
var productImagePanel = new
YAHOO.com.mydomain.widget.ProductImagePanel(obj.ge t('name'));
productImagePanel.initWithSkuCode(obj.get('name')) ;
};

YAHOO.util.Event.addListener(elements[i], "click", fnCallback, el);
}
}

YAHOO.util.Event.addListener(window, "load", initProductImagePanels);
})();
---------------------

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...


Nov 3 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
maya wrote:
>
(function() {
function initProductImagePanels() {
var elements =
YAHOO.util.Dom.getElementsByClassName('productImag e', 'img');

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

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

var fnCallback = function(e, obj) {
var productImagePanel = new
YAHOO.com.mydomain.widget.ProductImagePanel(obj.ge t('name'));
productImagePanel.initWithSkuCode(obj.get('name')) ;
};

YAHOO.util.Event.addListener(elements[i], "click",
fnCallback, el);
}
}

YAHOO.util.Event.addListener(window, "load", initProductImagePanels);
})();
---------------------

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..

Nov 3 '08 #2

P: n/a
On Nov 3, 3:27*pm, maya <maya778...@yahoo.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.
Nov 3 '08 #3

P: n/a
On Nov 3, 3:46*pm, maya <maya778...@yahoo.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.
Nov 3 '08 #4

P: n/a
Jorge wrote:
On Nov 3, 3:27 pm, maya <maya778...@yahoo.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..
Nov 3 '08 #5

P: n/a
Jorge wrote:
On Nov 3, 3:46 pm, maya <maya778...@yahoo.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.ProductImage = 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...:)
Nov 3 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.