zoukankan      html  css  js  c++  java
  • 函数化1

     1 var mammal = function(spec) {
     2         var that = {};
     3 
     4         that.saying = function() {
     5             return spec.saying;
     6         };
     7 
     8         that.get_name = function() {
     9             return spec.name;
    10         };
    11 
    12         that.says = function() {
    13             return this.saying();
    14         };
    15 
    16         return that;
    17     };
    18 
    19 var myMammal = mammal({
    20     name: 'Herb',
    21     saying: 'Hello world!!!'
    22 });
    23 
    24 console.log(myMammal.says());

    DC大牛果然对javascript的理解非常透彻,javascript语言精粹真的物超所值,虽然此书很薄。

     1 var mammal = function(spec) {
     2         var that = {};
     3 
     4         that.get_name = function() {
     5             return spec.name;
     6         };
     7 
     8         that.says = function() {
     9             return spec.saying();
    10         };
    11 
    12         return that;
    13     };
    14 
    15 var myMammal = mammal({
    16     name: 'Herb',
    17     saying: function() {
    18         return 'Hello world!!!'
    19     }
    20 });
    21 
    22 console.log(myMammal.says());
  • 相关阅读:
    css
    团队介绍
    day4
    线段树懒标记
    P2014选课
    P2015
    扩展欧几里得(exgcd)求解不定方程/求逆元
    transform和tolower
    快读
    bzoj2118
  • 原文地址:https://www.cnblogs.com/qzsonline/p/2589748.html
Copyright © 2011-2022 走看看