Home > Web Front-end > JS Tutorial > 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

高洛峰
Release: 2016-12-08 14:39:27
Original
1393 people have browsed it

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>
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template