1
我有代碼在下面,我想我的結果是「Hello Mr. John Doe」。呼叫反應功能不起作用
function formatname(name) {
return name.fullName;
};
const name = {
firstName: 'John',
lastName: 'Doe',
fullName: function() {
return this.firstName + ' ' + this.lastName;
}
};
const getName = (
<h1>Hello Mr. {formatname(name)}</h1>
);
ReactDOM.render(
getName,
document.getElementById('root')
);
但是,當我保存它返回的是「你好先生」,我在變量fullName中出了什麼問題。
謝謝,它工作。你可以給我打電話「.blind(name)()是什麼意思? – HungNguyen
請參閱:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind The bind()方法創建一個新函數,該函數在調用時將其關鍵字設置爲提供的值,並在調用新函數時提供的任何參數序列之前提供給定序列的參數。 –