zoukankan      html  css  js  c++  java
  • 6 ways to define javascript function

    There are six ways/contexts in which to create functions:

    1) Standard declarative notation (most familiar to people with C background)

    function foo(){}

    All the rest are function expressions:

    2) As a method of an object literal

    var obj ={
        foo:function(){}};

    3) As a method of an instantiated object (created each time new is exectued)

    varObj=function(){this.foo =function(){};};

    4) As a method of a prototype (created only once, regardless of how many times new is executed)

    varObj=function(){};Obj.prototype.foo =function(){};

    5) As an anonymous function with a reference (same effect as #1) *

    var foo =function(){};

    6) As an immediately executed anonymous function (completely anonymous)

    (function(){})();

    * When I look at this statement, I consider the result. As such, I don't really consider these as anonymous, because a reference is immediately created to the function and is therefore no longer anonymous. But it's all the same to most people.

    see also :

    http://stackoverflow.com/questions/1866084/javascript-function-declaration

    http://shichuan.github.com/javascript-patterns/

  • 相关阅读:
    python刷新七牛云CDN缓存
    python 操作redis
    redis 设置密码
    redis 允许其他机器连接设置方法
    redis持久化
    redis操作
    redis简介及与memcached比较
    dataframe 处理某列的小数位数并加特殊符号
    django 生成和下载CSV文件
    django 重定向
  • 原文地址:https://www.cnblogs.com/malaikuangren/p/2956318.html
Copyright © 2011-2022 走看看