Home  >  Article  >  Web Front-end  >  Use json to define functions, in which you can define the implementation methods of multiple functions

Use json to define functions, in which you can define the implementation methods of multiple functions

高洛峰
高洛峰Original
2016-12-08 14:39:271333browse

As shown below:

<script>
  //普通方法
  function add(a,b){
      return a+b;
  }
  add(3,4);
  //使用json来定义函数,在里面可以定义多个函数
  var method={
          add:function(a,b){
              return a+b;
          },
          add2:function(a,b){
              return a+b;
          },
          add3:function(a,b){
              return a+b;
          },
  };
  var temp = method.add2(31, 4);
  alert(temp);
</script>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn