zoukankan      html  css  js  c++  java
  • 23-angular.noop

    一个不执行任何操作的空函数。这个函数一般用于函数风格。

    一个不执行任何操作的空函数。这个函数一般用于函数风格。

    格式:angular.noop();

    (function () {
        angular.module("Demo", [])
        .controller("testCtrl", testCtrl);
        function testCtrl() {
          var _console = function (v) {
              return v * 2;
          };
          var getResult = function (fn, val) {
              return (fn || angular.noop)(val);
          };
          var firstResult = getResult(_console, 3);//6
          var secondResult = getResult(null, 3);//undefined
          var thirdResult = getResult(undefined, 3);// undefined
        };
      }())

    区别于angular.identity()

    (function () {
        angular.module("Demo", [])
        .controller("testCtrl", testCtrl);
        function testCtrl() {
             var getResult = function (fn, val) {
              return (fn || angular.identity)(val);
          };
          var result = getResult(function (n) { return n * 2; }, 3); //  result = 6
          var null_result = getResult(null, 3);//  null_result = 3
          var undefined_result = getResult(undefined, 3);// undefined _result = 3
        };
      }())
  • 相关阅读:
    07组 Beta冲刺 (2/5)
    第07组 Beta冲刺 (1/5)
    第07组 Alpha冲刺 总结
    ES相关
    集群与分布式
    idea使用总结
    Tomcat配置与启动与访问
    Web基础
    B/S与C/S架构
    一周视频学习总结
  • 原文地址:https://www.cnblogs.com/ms-grf/p/6979432.html
Copyright © 2011-2022 走看看