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
        };
      }())
  • 相关阅读:
    2021-5-14 日报博客
    2021-5-13 日报博客
    2021-5-11 日报博客
    2021-5-10 日报博客
    2021-5-8 周报博客
    团队介绍——北部大队
    周总结4
    梦断代码阅读笔记02
    周总结3
    周总结2
  • 原文地址:https://www.cnblogs.com/ms-grf/p/6979432.html
Copyright © 2011-2022 走看看