Java Foundation--javascript

Source: Internet
Author: User

Javascript: Object-and event-driven scripting language, primarily for client

    • Characteristics:
      • Interactivity: Dynamic interaction of information.
      • Security: Cannot access the local hard disk.
      • Cross-platform: JavaScript is supported as long as there is a browser, regardless of the platform.
    • How JavaScript and HTML are combined:
      • <script type= "Text/javascript" >...</script>
      • <script type= "Text/javascript" src= ".... js file"; Code is not executed </script>
    • Variable:
var x = 4; (no obvious type) 3140/1000*1000=3140typeof (123) = number "X" +1= "121" typeof ("abc") = string "" -1= "1" typeof (3.45 ) = number " -1=nan" (illegal character)
    • Operator and statement: while () {} if () {}else{} switch () {}
    • Written in HTML: document.write (""); Line break: document.write ("<br/>");
    • Functions: Function Show () {.... return ...;}. The function can be internally given a real parameter group, arguments[...], and with the length property. var sum = show, without brackets denotes sum function body
      • Dynamic function: var func = new Function ("X, Y", "sum=x+y;return sum;");
      • Anonymous functions: var func = function () {alert ("over");} is typically used for event invocation.
    • Scope of variables: only variables defined within a function are local variables, others are global. for (Var i=0;i<5;i++) {...} The I in is also a global variable.
    • Array: arr = [3,5,8]
      • Characteristics:
        • Containers for storing data
        • The length is variable.
        • The element type is arbitrary
      • Strings can be directly compared
      • var arr2=new Array (2); --Two arrays
      • var arr2 = new Array (3,9)--two arrays with 3 and 9 contents
    • You write a function, such as string comparison size, find the maximum value of the Getmax () function, you want to add to the tool class, you can:

Array.prototype.max = Getmax (); var Array = [3,5,8];

var ret = Array.max ();d ocument.write (ret);

You can also directly Array.prototype.max = function () {...; return;};

You can also use the. js file to import. js files in the. html you want to use, such as the trim () method.

String.prototype.trim = function () {    var start = 0,end = This.length-1;    while (Start <= end && This.charat (start) = = "") {        start++;    }    while (Start <=end && this.charat (end) = = "") {        end--;    }    Return this.substring (start,end);};
    • JavaScript Object-oriented:
The function person (x, y) {///equals the definition class    this.age = x;    THIS.name = y;    This.show = function () {...};      } var p = new Person (...,...);  P.number = xxx; Arbitrarily join attribute members

The person class can also add new features, Person.prototype.toString = function () {...};

    • JavaScript-specific statements:
      • P1.set (); --With (p1) {

P1.get (); --set (); Get ();}

      • For (variable in object) {}--for traversing objects and arrays, such as for (X in P1) {alert (x+ ":" +p1[x]);} You can traverse the output properties and methods.

              

Java Foundation--javascript

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.