91 captures
13 Sep 2006 - 14 Nov 2025
Jul AUG Sep
17
2020 2021 2022
success
fail

About this capture

COLLECTED BY

Organization: Internet Archive

The Internet Archive discovers and captures web pages through many different web crawls. At any given time several distinct crawls are running, some for months, and some every day or longer. View the web archive through the Wayback Machine.

Collection: Wide Crawl Number 18

TIMESTAMPS

The Wayback Machine - http://web.archive.org/web/20210817155054/https://ms.wikipedia.org/wiki/JavaScript
 





JavaScript



Daripada Wikipedia, ensiklopedia bebas.



Pergi ke navigasi  Pergi ke carian  

JavaScript adalah nama milik Syarikat Komunikasi Netscape dan sekarang adalah pelaksanaan berpiawai ECMAScript untuk Pertubuhan Mozilla. Bahasa ini amat popular kerana terdapat banyak penggunaannya pada laman-laman web (sebagai JavaScript pihak pelanggan).

Ramai yang beranggapan bahawa JavaScript adalah "Java yang ditafsir" walaupun pada hakikatnya tidak sebegitu. Malah, walaupun namanya serupa, kaitan antara JavaScript dengan Java adalah jauh sekali. Sintaksis JavaScript diilhamkan dari Java dan C untuk memudahkan pengguna baru mempelajarinya.

Sejarah[sunting | sunting sumber]

Pada asalnya, pembangunan JavaScript diusahakan oleh Brendan Eich di bawah nama Mocha, kemudiannya ditukar kepada LiveScript, dan akhirnya ditukar kepada JavaScript. Perubahan nama dari LiveScript ke JavaScript adalah berkebetulan dengan langkah Netscape menambah sokongan teknologi Java di pelayar web Netscape Navigator keluarannya. JavaScript mula diperkenalkan dan dipasang di pelayar Netscape versi 2.0B3 pada Disember 1995.

Pada tahun 2011, versi terakhir bagi JavaScript ialah 1.8.5

Sintaks dan simantik[sunting | sunting sumber]

Sehingga 2009, versi terbaru bagi bahasa ini ialah JavaScript 1.8.1. Ia merupakan superset bagi ECMAScript (ECMA-262) Edition 3. Sambungan kepada bahasa berkenaan, termasuklah sokongan separa untuk E4X (ECMA-357) dan tampilan-tampilan eksperimental yang diambil kira untuk disertakan dalam edisi-edisi ECMAScript masa hadapan, didokumentasikan di sini.[2]

Contoh mudah[sunting | sunting sumber]

Fungsi rekursif ringkas:

function factorial(n) {
    if (n === 0) {
        return 1;
    }
    return n * factorial(n - 1); 
}

Skrip aluan ringkas:

var nama = prompt("Nama anda siapa?");
alert("Selamat datang "+nama);

Sintaks fungsi awanama (atau lambda):

function add (i, j) {
    var add_pri = function (x, y) {
        return x + y;
    };

    return add_pri(i, j);
}

Penutupan:

function showclosure () {
    var inc = makeinc(1);

    inc(); // 1
    inc(); // 2
    inc(); // 3
}

function makeinc (initialValue) {
    var count = initialValue;

    return function () {
        return count++;
    };
}

Demonstrasi fungsi variadik. 1 akan dialert, kemudian 2, seterusnya 3. arguments merupakan pemboleh ubah khas.

function unlimited_args () {
    for (var i = 0; i < arguments.length; i++) {
        alert(arguments[i]);
    }
}

unlimited_args(1, 2, 3);

Contoh yang lebih rumit[sunting | sunting sumber]

Kod sampel ini menunjukkan pelbagai tampilan-tampilan JavaScript.

/* Finds the lowest common multiple of two numbers */
function LCMCalculator (x, y) { // constructor function
    var checkInt = function (x) { // inner function
        if (x % 1 !== 0) {
            throw new TypeError(x + "is not an integer"); // exception throwing
        }
        return x;
    };
    this.a = checkInt(x)
    // ^ semicolons are optional (but beware since this may cause consecutive lines to be
    //erroneously treated as a single statement)
    this.b = checkInt(y);
}
// The prototype of object instances created by a constructor is 
// that constructor's "prototype" property.
LCMCalculator.prototype = { // object literal
    constructor : LCMCalculator, // when reassigning a prototype, set the constructor property appropriately
    gcd : function () { // method that calculates the greatest common divisor
        // Euclidean algorithm:
        var a = Math.abs(this.a), b = Math.abs(this.b), t;
        if (a < b) {
            // swap variables
            t = b; 
            b = a; 
            a = t; 
        }
        while (b !== 0) {
            t = b;
            b = a % b;
            a = t;
        }
        // Only need to calculate gcd once, so "redefine" this method.
        // (Actually not redefinition - it's defined on the instance itself,
        // so that this.gcd refers to this "redefinition" instead of LCMCalculator.prototype.gcd.)
        // Also, 'gcd' == "gcd", this['gcd'] == this.gcd
        this['gcd'] = function () { 
            return a; 
        };
        return a;
    },
    "lcm" /* can use strings here */: function () {
        // Variable names don't collide with object properties, e.g. |lcm| is not |this.lcm|.
        // not using |this.a * this.b| to avoid FP precision issues
        var lcm = this.a / this.gcd() * this.b; 
        // Only need to calculate lcm once, so "redefine" this method.
        this.lcm = function () { 
            return lcm; 
        };

        return lcm;
    },
    toString : function () {
        return "LCMCalculator: a = " + this.a + ", b = " + this.b;
    }
};

// Note: Array's map() and forEach() are predefined in JavaScript 1.6.
// They are currently not available in the JScript engine built into
// Microsoft Internet Explorer, but are implemented in Firefox, Chrome, etc.
// They are used here to demonstrate JavaScript's inherent functional nature.

[[25, 55],[21, 56],[22, 58],[28, 56]].map(function (pair) { // array literal + mapping function
    return new LCMCalculator(pair[0], pair[1]);
}).sort(function (a, b) { // sort with this comparative function
    return a.lcm() - b.lcm();
}).forEach(function (obj) {
    /* Note: print() is a JS builtin function available in Mozilla's js CLI;
     * It is functionally equivalent to Java's System.out.println().
     * Within a web browser, print() is a very different function
     * (opens the "Print Page" dialog),
     * so use something like document.write() or alert() instead.
     */
    // print       (obj + ", gcd = " + obj.gcd() + ", lcm = " + obj.lcm());
    // alert       (obj + ", gcd = " + obj.gcd() + ", lcm = " + obj.lcm());
    document.write(obj + ", gcd = " + obj.gcd() + ", lcm = " + obj.lcm() + "<br />");
});

Keluaran berikut sepatutnya akan dipaparkan pada tetingkap pelayar.

LCMCalculator: a = 28, b = 56, gcd = 28, lcm = 56
LCMCalculator: a = 21, b = 56, gcd = 7, lcm = 168
LCMCalculator: a = 25, b = 55, gcd = 5, lcm = 275
LCMCalculator: a = 22, b = 58, gcd = 2, lcm = 638

Jika Internet Explorer digunakan, contoh tadi akan menghasilkan ralat. Dengan itu, contoh tadi menunjukkan bahawa pentafsir JScript bagi Internet Explorer melakukan kod dengan cara berbeza berbanding pentafsir JavaScript dan ECMAScript dalam pelayar web lain. (Lihat ulasan dalam kod sumber untuk perincian perbezaan yang relevan bagi contoh ini.)

Lihat juga[sunting | sunting sumber]

Rujukan[sunting | sunting sumber]

  1. ^ New in JavaScript 1.8.5 | Mozilla Developer Network
  • ^ "About - MDC". Developer.mozilla.org. 2008-08-31. Dicapai pada 2009-05-19.
  • Pautan luar[sunting | sunting sumber]

    Diambil daripada "https://ms.wikipedia.org/w/index.php?title=JavaScript&oldid=3119835"

    Kategori: 
    Pages using deprecated source tags
    JavaScript
    Bahasa penskripan
     





    Menu pandu arah


    Alat peribadi  



    Belum log masuk
    Perbincangan
    Sumbangan
    Buka akaun
    Log masuk
     

    Ruang nama  



    Rencana
    Perbincangan
     

    Kelainan  





    Rupa  



    Baca
    Sunting
    Sunting sumber
    Lihat sejarah
     

    Lagi  






     







    Pandu arah  



    Laman Utama
    Tinjau
    Hal semasa
    Rencana rawak
     

    Perhubungan  



    Tentang Wikipedia
    Portal masyarakat
    Perubahan terkini
    Hubungi kami
    Menderma
    Bantuan
    Kedai Kopi
     

    Peralatan  



    Pautan ke laman ini
    Perubahan berkaitan
    Muat naik fail
    Laman khas
    Pautan kekal
    Maklumat laman
    Petik laman ini
    Butir Wikidata
     

    Cetak/eksport  



    Cipta buku
    Muat turun sebagai PDF
    Versi boleh cetak
     

    Dalam projek lain  



    Wikimedia Commons
    Wikibooks
     

    Dalam bahasa lain  



    Afrikaans
    Ænglisc
    العربية
    Aragonés
    Asturianu
    Azərbaycanca
    Bahasa Indonesia

    Bân-lâm-gú
    Беларуская
    Беларуская (тарашкевіца)
     
    Български
    Català
    Чӑвашла
    Čeština
    Dansk
    Deutsch
    Eesti
    Ελληνικά
    English
    Español
    Esperanto
    Euskara
    فارسی
    Français
    Galego
    /Hak-kâ-ngî

    Հայերեն
    ि
    Hrvatski
    Interlingua
    Íslenska
    Italiano
    עברית
    Jawa

    Қазақша
    Кыргызча
    Kiswahili
    Latviešu
    Lietuvių
    Lingua Franca Nova
    Lombard
    Magyar
    Македонски


    مصرى
    مازِرونی
    Mìng-dĕ̤ng-nḡ
    Монгол

    Nederlands


    Nordfriisk
    Norsk bokmål
    Oʻzbekcha/ўзбекча
    پنجابی

    Polski
    Português
    Română
    Русский
    Саха тыла
    Scots
    Shqip

    Simple English
    Slovenčina
    Slovenščina
    کوردی
    Српски / srpski
    Srpskohrvatski / српскохрватски
    Sunda
    Suomi
    Svenska
    Tagalog
    ி
    Taqbaylit
    Татарча/tatarça

    Tetun

    Tiếng Vit
    Тоҷикӣ
    Türkçe
    Türkmençe
    Українська
    اردو
    Vèneto



    Žemaitėška


    Sunting pautan
     



    Laman ini kali terakhir disunting pada 06:31, 15 April 2013.

    Teks disediakan dengan Lesen Creative Commons Pengiktirafan/Perkongsian Serupa; terma tambahan mungkin digunakan. Lihat Terma Penggunaan untuk butiran lanjut.



    Dasar privasi

    Perihal Wikipedia

    Penafian

    Paparan mudah alih

    Pembangun

    Statistik

    Kenyataan kuki



    Wikimedia Foundation
    Powered by MediaWiki