text POO JS 2

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text POO JS 2相关的知识,希望对你有一定的参考价值。

const assert = require('assert');

class BankCustomer {
    constructor (name, code) {
        var enteredPin = '3579';
        this.name = name;
        this.code = code;
        this.getPin = () => enteredPin;
    }

    getName() {return `${this.name}`;}
    verifyPinInput() {
        if (this.code === this.getPin()) {return true;
        } else {return false;
        }        
    }
}

// Tests
const customer = new BankCustomer('John Doe', '3579');
assert.equal(typeof customer.getName, 'function');
assert.equal(typeof customer.verifyPinInput, 'function');
assert.equal(customer.getName(), 'John Doe');
assert.ok(customer.verifyPinInput('3579'));

以上是关于text POO JS 2的主要内容,如果未能解决你的问题,请参考以下文章

text 挑战POO en JS 2封装

text POO js2

text poo js1

text poo_js

text POO en JS 1

javascript POO zh了JS 2 - 封装