函数式编程(误)

代码 -- 函数式编程

function test (x) {
    this.__value = x;
}

test.prototype.of = function (x) {
    return new test(x)
}

test.prototype.isValid = function () {
    this.__value = this.__value >>> 0
    return this.__value
}

test.prototype.map = function (v) {
    return this.isValid() ? this.of(v(this.__value)) : this.of("-");
}

console.log(new test(2**32).map(v => (v === 1 ? '一课' : '主题')).__value)

// output : '-'
// 1 => '一课', not 1 => '主题'
posted @ 2021-09-01 10:16  MerLin97  阅读(13)  评论(0编辑  收藏  举报