【发布时间】:2018-12-03 12:36:31
【问题描述】:
下面的代码sn-p展示了几个方法调用的对比。
console.clear();
const al = (sub, property) => (state) => (state[sub][property]);
const getPatient = (property) => al('patient', property);
const getAppointment = (property) => al('appointment', property);
const state = {
patient: {name: 'jos', lastname: 'ke'},
appointment: {date: '01-01-1900'},
};
getPatient('name') === getPatient('lastname'); // should evaluate to false
getPatient('name') === getAppointment('date'); // should evaluate to false
getPatient('name') === getPatient('name'); // should evaluate to true, but is false
但是,我希望最后一个比较结果为true。我们如何编写比较结果使其评估为true?
【问题讨论】:
标签: javascript function compare closures