zoukankan      html  css  js  c++  java
  • js返回函数, 函数名后带多个括号的用法及join()的注意事项

    题目描述

    实现函数 functionFunction,调用之后满足如下条件:
    1、返回值为一个函数 f
    2、调用返回的函数 f,返回值为按照调用顺序的参数拼接,拼接字符为英文逗号加一个空格,即 ‘, ‘
    3、所有函数的参数数量为 1,且均为 String 类型
    示例1

    输入

    functionFunction('Hello')('world')

    输出

    Hello, world
    以下是我写的答案
    1. function functionFunction(str) {
    2. var f = function(a) {
    3. var b = [str];
    4. b.push(a);
    5. return b.join(", ");
    6. // return str + ", " + a;
    7. }
    8. return f;
    9. }
    10. console.log(functionFunction('Hello')('world'));//Hello, world

    刚开始一看输入functionFunction(‘Hello’)(‘world’) , 函数名后带有2个括号且带有参数,有点懵逼。后经测试得后面的为子函数的参数,即a;

    functionFunction(‘Hello’)(‘world’)(‘!’);

    经测试为函数f中的子函数的参数,如果你需要的话。

    还有关于join()的用法,它为数组原型上的方法…….不是字符串的方法。所以需要将其转换为Array类型。当然直接拼接字符串更简单!!

  • 相关阅读:
    开发servlet三种方式
    puppet 启动失败
    linux 内核 中链表list
    software level
    ubuntu 使用 root “sudo /bin/bash”
    linux 内存管理
    linux kernel "current" macro
    hello.hs haskell
    ubuntu samba
    微信小程序中使用 npm包管理 (保姆式教程)
  • 原文地址:https://www.cnblogs.com/ljk001/p/7999961.html
Copyright © 2011-2022 走看看