Javasript Learning Notes

Source: Internet
Author: User
Tags closure
if (typeof (TEMP2) = = ' undefined ') {
   alert ("AAA");
 }
  if ("" +temp2== ' undefined ') {
    alert ("fff");
  }
Static functions can only be taken to static values
<script type= "Text/javascript" >
   
   var t = one;
   function Para () {
      this.b=1;
   }
   para.prototype.c=2;
   para.a=10;
   
   Para.haha = function () {
     alert (THIS.A);
     alert (THIS.C);
 alert (this.b);
 alert (THIS.T);
  };
  Para.haha ();
  </script>
   var t = one;
   function Para () {
      this.b=1;
   }
   para.prototype.c=2;
   para.a=10;
   Para.haha = function () {
     function temp () {
     alert (THIS.A);     This means that the global function is not para
     alert (THIS.T);
 }
    Temp ();
  };
  Para.haha ();
  
  
  
  var x = "global"; 
function f () { 
    var x = ' local '; 
    alert (this.x);
} 
    f ();  The global      function, this is always meant to be globally variable, and functions and objects are different, to be distinguished from closures
<script type= "Text/javascript" >
   
   var t = one;
   function Para () {
    this.a=10;
   }
  para.b=20;
  Para.getpoo=function () {
     alert (this.b);
     alert (THIS.A);
     alert (THIS.T);
  }
 var result = Para.getpoo;   Re-assign to the other variable, this points to the global variable result
 ();
  </script>
  
  
  
   var d = $ (' <div/> '). Appendto ($ (document.body));
   d.html (data). Omdialog
  
  
  
  
   var tpl = ' <tr> ' + 
                  ' <td><input name= ' pname{0} ' type= ' text '/></td > ' + 
                  ' <td><input name= ' pvalue{0} ' type= ' text '/></td> ' + 
                  ' <td><a onclick= ' Removeattr (this); " > Delete </a></td> ' + 
              ' </tr> ';
    function addcattr () {
        cindex++;
        var r = $ (Tpl.format (CIndex));
        R.find (' input '). each (the function () {
            var _el = $ (this);
            _el.keyup (function () {
                validatenotempty (_el);
            }). Blur (function () {
                validatenotempty (_el);
            });
        $ (' #attrTbl tbody '). Append (R);
    }
 <script type= "Text/javascript" >
 if (!window. Monitor) {window.
   Monitor = {_id:1, id:function () {return this._id++;}
 } (function (M) {M.ds = {/+ adds DS object A: "A-1", B: "B-1"}) (monitor) to monitor;  window. $m = Monitor.ds;  This is declared as a Window object, can be directly referenced in the DOM element if it is Var, can only be referenced in JS, so that initialization action, event trigger action can be packaged in the module alert ($m. a);  
  Alert ($m. b);
    </script> <script> window. $m = Monitor.panel;
    $m. BaseURL = ' ${contextpath} ';
    $m. Resurl = ' ${resbase} ';
    $m. expressinstall= $m. resurl+ "/scripts/charts/flash/expressinstall.swf";
    $m. amlinechart= $m. resurl+ "/scripts/charts/flash/amline.swf";
    $m. Panles = eval (' ${panels} ');
    $m. Fixlength = ' ${size} ';
    var map = new Monitor.hashmap (); Map.put ("Jtamonitorserviceimpl", New $m. Flashparam ("/protect/monitor/jta/statistics", "/scripts/charts/config/
    Line.xml "));
    $m. Watchmap=map;
$m. Initpanels (); 
</script> <script type= "Text/javascript" > var x = "global";function f () {var x = ' local ';    function g () {alert (x);} alert (this.x); 
This is the global variable in the closure, and the closure refers to the memory not releasing//This refers to the lexical scope, find the function of x g (); } f (); Calling this function displays ' local '
  </script>
  
  
  
<script type= "text/javascript" >
 function Bar () {return
    2;
}
var t =new Bar (); Returns the newly created object
alert (t);
var B = Bar ();  Returns a value of 2
alert (b);
</script>
<script type= "Text/javascript" >
   //object Nesting declaration
    var o = {
   A: "1",
   B: "2",
   c:{
      C1: "CC"
   }
}
alert (O.A);
alert (O.C.C1);
</script>
<script type= "Text/javascript" >
 var x = 1;
    
 if (true) {
   var x = 2;
}
 alert (x); 2 scopes are global, not scopes in functions
</script>

This is a common property page that makes scrolling code in JavaScript. Visible area Wide: document.body.clientwidth; Web page visible Area high: document.body.clientheight; Web page visible area wide: document.body.offsetwidth    (including the width of the sideline); High: document.body.offsetheight  of the visible area of the Web page (including the width of the sideline); Web page body Full text wide: document.body.scrollwidth; Full text of the Web page high: document.body.scrollheight; Web pages are rolled up high: document.body.scrolltop;  covered height Web pages are rolled away left: document.body.scrollleft; : window.screentop; on the body part of the Web page Page body part left: window.screenleft; High: window.screen.height; of screen resolution Wide: window.screen.width; of screen resolution Screen Available Workspace height: window.screen.availheight;
This.container.scroll (function () {
                var scrollhight = _t.container[0].scrollheight;
                var scrolltop = _t.container[0].scrolltop;
                var height = _t.container.height ()//fixed height to make the following equation set up, if the div is constantly growing can not calculate, the general let div length fixed, overflow:sroll
                // Load subsequent data when the scroll bar is 100 pixels from the bottom
                if (scrolltop + height >= scrollHight-100 && _t._hasmoredata) {
                    _t.fetchlogs ();
                }
            });

The JS constructor 
var Class = {
    create:function () {return
        function () {
            this.initialize.apply (this, arguments );
        }
    }
}
Class uses the following
var A = Class.create ();
A. prototype={
    initialize:function (v) {this
        . Value=v
    }
    Showvalue:function () {
        alert (this.value);
    }
}
var a = new A (' helloword! ');
A. Showvalue ()//Popup dialog box Helloword.

The pop-up layer can first create a div,url point to a page, take out the contents
of the page into the Div, because it is dynamic loading, this layer is closed to destroy
things
function Modifylistener (name) {
        $.ajax ({
            URL: ' ${baseurl}/modify ',
            data: {
                name:name
            },
            success:function (data) {
                Mindex =-1;
                var d = $ (' <div/> '). Appendto ($ (document.body));
                d.html (data). Omdialog ({ 
;

(function ($) {/** * * * * Adds a string's format method to format the string. * * Example: "A{0}b{0}c{1}" the result of format (' * * *, 123) is: a***b***c123 * */String.prototype.format = function (args) {var str = t
His  if (Arguments.length = = 0) {return str;} for (var i = 0; i < arguments.length; i++) {var re = new RegExp (' \\{' + i +
' \} ', ' GM ');
str = str.replace (Re, arguments[i]);
return str;
};
 /** * * Add the Trim method of the string to remove the space at the beginning and end of the string. * * Example: "A BC". The result of Trim () is: a BC */String.prototype.trim = function () {return this.replace (/^\s*) | (
\s*$)/g, ""); Function.prototype.createDelegate = function (context) {var _t = this; return function () {_t.apply (context, arguments);}
;
}; if (!window. aasmonitor) {window. Aasmonitor = {_id:1, id:function () {return this._id++;}, Mixin:function (target, source) {for (k in source) {Tar
GET[K] = source[k];
return target; }, Markflderror:function (EL, msg) {This.clearflderror (EL); if (msg) {$ (EL). addclass (' error '); var em = $ (' ; span class= "errorMsg ">{0}</span>". Format (msg);
$ (EL). After (EM); $ (EL). MouseOver (function () {em.show ();}).
Mouseout (function () {em.hide ();}); }, Clearflderror:function (EL) {var next = $ (EL). Next () while (Next.hasclass (' errormsg ')) {next.remove (); next = $ (E
L). Next ();
} $ (EL). Removeclass (' error ');
$ (EL). Unbind (' MouseOver '). Unbind (' mouseout '); }, Info:function (content) {$.ommessagetip.show ({content:content, timeout:2000});}, Warn:function (content) {$.
Ommessagetip.show ({content:content, type: ' warn '}); }, Error:function (content) {$.ommessagetip.show ({content:content, type: ' ERROR '});}, Hashmap:function () {var s
ize = 0;
var entry = new Object ();
This.put = function (key, value) {if (!this.containskey (key)) {size++} Entry[key] = value;
This.get = function (key) {if (This.containskey (key)) {return entry[key];} else {return null;}};
This.remove = function (key) {if (delete Entry[key]) {size--}}; This.containskey = function (key) {return (key in ENtry);
}; This.containsvalue = function (value) {for (Var prop in entry) {if (entry[prop] = = value) {return true;}}
;
}; This.values = function () {var values = new Array (size), for (Var prop in entry) {Values.push (entry[prop));
Es
};
This.keys = function () {var keys = new Array (size); for (Var prop. Entry) {Keys.push (prop);} return keys;};
This.size = function () {return size;};
}
};
 }) (JQuery);



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.