Article View: pl.comp.lang.javascript
Article #50976Re: Funkcja korzystająca z instrukcji switch
From: Rafal
Date: Mon, 09 Jan 2012 22:59
Date: Mon, 09 Jan 2012 22:59
100 lines
3772 bytes
3772 bytes
On Jan 9, 10:25 am, "NKAB -" <n...@NOSPAM.gazeta.pl> wrote:
> Rafal <wawrzynia...@gmail.com> napisa³(a):
>
>
>
>
>
>
>
>
>
>
>
> > Nie wiem jak po=B3=B1czy=E6 switch z funkcj=B1. Stworzy=B3em co=B6
> takiego,=
> > a
> > dok=B3adniej uzupe=B3ni=B3em funkcj=EA i instrukcj=EA switch jednak co=B6
> j=
> > est
> > =BCle. Nie mam pomys=B3u w jaki spos=F3b por=F3wna=E6 warto=B6ci
> instrukcji=
> > switch
> > w funkcji detectType.
> > Prosz=EA o pomoc.
>
> > // Example switch statement. typeof returns the type
> > // of the value as a string. For example, the type of
> > // a string is 'string', the type of a number is
> > // 'number', and the type of an object is 'object'.
> > switch (typeof 'foo') {
> > case 'string':
> > // some code
> > // If you don't return in the block, you should
> > // always have a break afterwards.
> > break;
> > case 'number':
> > break;
> > case 'object':
> > break;
> > default:
> > //block
> > }
>
> > // Write a function that uses switch statements on the
> > // type of value. If it is a string, return 'str'. If it
> > // is a number, return 'num'. If it is an object, return
> > // 'obj'. If it is anything else, return 'other'.
> > function detectType(str, num, obj, other) {
> > if(typeof =3D=3D=3D 'string'){
> > return str;
> > }
> > else if(typeof =3D=3D=3D 'number'){
> > return num;
> > }
> > else if(typeof =3D=3D=3D 'object'){
> > return obj;
> > }
> > else{
> > return other;
> > }
> > }
>
> Np tak:
>
> <script>
>
> zm1="aaa";
> zm2=123;
> var zm3 = new Array();
> var zm4;
>
> dT(zm1);
> dT(zm2);
> dT(zm3);
> dT(zm4);
>
> function dT(cos)
> {
>
> z=typeof(cos);
>
> switch(z)
> {
> case 'string': alert(z); break;
> case 'number': alert(z); break;
> case 'object': alert(z); break;
> default: alert('nic...'); break;
> }
>
> }
>
> </script>
>
> Andrzej.
>
> --
> Wys³ano z serwisu Usenet w portalu Gazeta.pl ->http://www.gazeta.pl/usenet/
Dzięki wielkie,
teraz już wszystko rozumiem
Technical Details
Message-ID:
<4aafc4ca-deed-4db9-a26e-3a55920744fb@cs7g2000vbb.googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!news2.euro.net!209.197.12.242.MISMATCH!nx01.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!cs7g2000vbb.googlegroups.com!not-for-mailReferences:
<a06e9e8f-2ae6-41a8-b804-31e3ef49e304@d10g2000vbh.googlegroups.com> <jeebqu$2r0$1@inews.gazeta.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!news2.euro.net!209.197.12.242.MISMATCH!nx01.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!cs7g2000vbb.googlegroups.com!not-for-mail From: Rafal <wawrzyniak.r@gmail.com> Newsgroups: pl.comp.lang.javascript Subject: Re: Funkcja korzystająca z instrukcji switch Date: Mon, 9 Jan 2012 14:59:14 -0800 (PST) Organization: http://groups.google.com Lines: 104 Message-ID: <4aafc4ca-deed-4db9-a26e-3a55920744fb@cs7g2000vbb.googlegroups.com> References: <a06e9e8f-2ae6-41a8-b804-31e3ef49e304@d10g2000vbh.googlegroups.com> <jeebqu$2r0$1@inews.gazeta.pl> NNTP-Posting-Host: 79.191.2.197 Mime-Version: 1.0 X-Trace: posting.google.com 1326149954 30259 127.0.0.1 (9 Jan 2012 22:59:14 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 9 Jan 2012 22:59:14 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: cs7g2000vbb.googlegroups.com; posting-host=79.191.2.197; posting-account=7vwMhgoAAAD8wq8C1DuyZCbGReJHVqmH User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HNKUARELSC X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7,gzip(gfe) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit