无标题文章

Javascript

1. 请优化这段代码 ,提高可读性

function async_add (m, n, callback) {
    setTimeout(callback.bind(null, m+n), 500);
}

async_add(1, 2, function (res) {
    console.log(res);
    async_add(res, 3, function (res) {
        console.log(res);
        async_add(res, 5, function (res) {
            console.log(res);
            async_add(res, 10, function (res) {
                console.log(res);
                async_add(res, 25, function (res) {
                    console.log(res);
                    async_add(res, 37, function (res) {
                        console.log(res);
                        async_add(res, 48, function (res) {
                             console.log(res);
                        })
                    })
                });
            });
        });
    });
});

2. 请给出这段代码 的运行结果,并解释为什么

class Animal {
    constructor(pos) {
        this.pos = pos;
    }
}

class Whale extends Animal {
constructor(pos) {
    super(pos + 1);
}
swim() {
    this.pos <<= 1;
    setTimeout(function timer() {
    this.pos <<= 1;
    this.pos < 8 && setTimeout(timer, 0);
    console.log(this.pos);
    }, 0);
    console.log(this.pos);
}
}

var pos = 1;
const whale = new Whale(pos);
whale.swim();

3. 请实现下段代码

/**
interface Array<T> {
    //flatMap :: (t -> [u]) -> [t] -> [u]
    flatMap<U>(f: (item: T) => U[]): U[];

}
*/

Array.prototype.flatMap = function (f) {
    // 实现这个函数,使得下面的测试用例能够正确输出
    throw new Error('Not implemented yet!')
    
}


/**
* 测试用例
*/

const arr1 = [1, 2, 3], arr2 = ['a', 'b', 'c']
const CartesianProduct = arr1.flatMap(x => arr2.flatMap(y => [[x, y]]))
//result => [[1, 'a'], [1, 'b'],  [1, 'c'],  [2, 'a'], [2, 'b'], [2, 'c'], [3, 'a'], [3, 'b'], [3, 'c']]


const flattenArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9]].flatMap(x => x)
//result => [1, 2, 3, 4, 5, 6, 7, 8, 9]

html/css

请根据此效果图,兼容现代浏览器,尽可能还原。 (不限框架,工具,预编译语言)

兼容性要求:Chrome / Firefox / IE 11 / Edge

zenmate_payment.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 第5章 引用类型(返回首页) 本章内容 使用对象 创建并操作数组 理解基本的JavaScript类型 使用基本类型...
    大学一百阅读 8,455评论 0 4
  • 百度首页 登录 注册 新闻网页贴吧知道音乐图片视频地图百科文库 进入词条搜索词条帮助 首页 分类 艺术 科学 自然...
    lmh829阅读 2,905评论 0 0
  • vue插件介绍 2. 插件分类 主要注册与绑定机制如下: export default{install(Vue...
    Osmond_wang阅读 2,642评论 0 1
  • HTML、XML、XHTML 的区别 HTML全名为**超文本标记语言**(Hyper Text Markup L...
    7a9d36c8963d阅读 1,813评论 0 0
  • 12项工作的基本能力,完美助力你的职场生涯 学习、工作和生活是每个人生命中的重要组成部分,而工作又在其中占有非常重...
    寒武纪2731阅读 9,266评论 11 144