473,805 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


Nov 3 '08 #1
5 1782
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..

Nov 3 '08 #2
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.
Nov 3 '08 #3
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.
Nov 3 '08 #4
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..
Nov 3 '08 #5
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...:)
Nov 3 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2705
by: G Matthew J | last post by:
http://htmatters.net/htm/1/2005/07/evaling-JSON.cfm This is more or less in response to Mr Crockford's admonition a few months ago, "fork if you must". Ironically, although in that usenet post he calls what I am suggesting "brittle", his own Javascript JSON parser is not valid JSON, but rather conforms to my proposed variation on JSON!! With an identifier prepended to the front of the JSON block, and function literals as values: see...
9
5573
by: Jim Washington | last post by:
I'm still working on yet another parser for JSON (http://json.org). It's called minjson, and it's tolerant on input, strict on output, and pretty fast. The only problem is, it uses eval(). It's important to sanitize the incoming untrusted code before sending it to eval(). Because eval() is evil http://blogs.msdn.com/ericlippert/archive/2003/11/01/53329.aspx apparently in every language. A search for potential trouble with eval() in...
27
2755
by: David Golightly | last post by:
This is just a quick poll for all you web devs out there: What browsers do you test on/are concerned about compatibility with? Obviously, you're going to test on current-generation browsers such as IE6, IE7, Firefox 1.5/2, Opera 8/9, Safari 2, etc. How old must a browser be before you stop worrying about it? Anybody here still test on IE4? Thanks,
1
2103
by: hedgehog | last post by:
I've always been a do-it-yourselfer when it comes to referencing DOM, doing lil animations and Ajax queries, etc, but I thought I'd give someone else's toolkit a spin. Aside from sorting out that jQuery's small and Script.aculo.us' home page animation doesn't always start in FF 2.0.0.3, I've no clue as to which toolkits are better suited to which tasks. Here's a general idea of the sorts of projects I'll be coding over the next year:
5
16137
by: Otto Wyss | last post by:
I've now been looking for a week for a simple but useful sample on how to get a list of entries (persons) via an XMLHttpRequest using Json/PHP on the server. So far I've found about a thousend different tutorials and code samples but not a single one, where the server returns an array of entries. Very few samples use Json at all and almost none show the server code. So does anybody know a sample which - uses just a small javascript...
2
3327
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until recently -- or maybe I should just speak for myself.) The fact that JSON is more elegant goes without saying, yet I can't seem to find a way to use JSON the way I *really* want to use it: to create objects that can be instantated into multiple...
11
2001
by: Jang | last post by:
Does anyone have an example of well written JavaScript applications that they know about? I would prefer the code to be readable. I particularly like YUI's code. Does anyone have any more applications/ examples? Thanks .
7
1443
by: My Pet Programmer | last post by:
Just a question in general, how do you guys feel about the YUI libraries from Yahoo? I've just noticed them, used one or two for a couple things, but I haven't dug too deep. http://developer.yahoo.com/yui/ ~A!
2
6361
by: embz | last post by:
this post concerns three pages. 1. this page: http://www.katherine-designs.com/sendemail.php i get the following errors: a lot of it seems to deal with the PHP code i inserted to the page. as my PHP skills are close to nil, i'm wary about fiddling with it myself. =\ 2. now this page: http://www.katherine-designs.com/contact.php
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10359
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10104
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.