JavaScript Design Pattern Series One

Source: Internet
Author: User

1. JavaScript Flexible language

Way One,

function CheckName () {} function Checkemail ()) {}function Checkpassword () {}

Way Two,

var checkname=function() {}var checkemail=function() {}  var checkpasswork=function() {}

Mode 11 and mode two are global scope variables, the way two can intuitively say that the function is also a variable in JavaScript, but the definition of the location is different

2. Using the object to incorporate variables

Way One,

var checkobject={    checkname:function() {},    Checkemail:  function() {},    Checkpassword:function() {}}

Way Two,

var function  functionreturn This function return this  functionreturnthis; }

3. True and False objects

var function () {    return  {        function  () {},        function  () { },        function  () {}}    }
var obj= checkobject ();
Obj.checkname ();

4. Class Form

var function () {    thisfunction  () {};      This function (){ };      This function (){ };} var New Checkobject (); Obj.checkname ();

5. Prototype form

Way One,

var function  functionfunction= function () {}

Way Two,

var function () {    return  {        function  () {},        function  () { },        function  () {}}    }

6. Prototype form plus Return

var function  functionreturn This function return this  functionreturnthis; }

Way Two,

var function () {    return  {        functionreturnthis;},         functionreturn this;},        functionreturn  This;}}    }

JavaScript Design Pattern Series One

Related Article

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.