File tree Expand file tree Collapse file tree 3 files changed +100
-100
lines changed
1-js/06-advanced-functions/11-currying-partials Expand file tree Collapse file tree 3 files changed +100
-100
lines changed Original file line number Diff line number Diff line change 11
22
3- 1 . Either use a wrapper function, an arrow to be concise :
3+ 1 . Có thể sử dụng hàm bao hoặc hàm mũi tên cho ngắn gọn :
44
55 ``` js
66 askPassword (() => user .login (true ), () => user .login (false ));
77 ```
88
9- Now it gets ` user` from outer variables and runs it the normal way .
9+ Đối tượng ` user` được lấy từ bên ngoài và chạy như bình thường .
1010
11- 2. Or create a partial function from `user.login` that uses `user` as the context and has the correct first argument :
11+ 2. Hoặc tạo một hàm riêng từ ` user.login` để sử dụng ` user` làm ` this ` :
1212
1313
1414 ` ` ` js
15- askPassword (user .login .bind (user, true ), user .login .bind (user, false ));
15+ askPassword(user.login.bind(user, true), user.login.bind(user, false));
1616 ` ` `
Original file line number Diff line number Diff line change @@ -2,13 +2,13 @@ importance: 5
22
33---
44
5- # Partial application for login
5+ # Tạo hàm riêng của hàm login
66
7- The task is a little more complex variant of < info:task/question-use-bind > .
7+ Bài tập này là phiên bản phức tạp hơn của < info:task/question-use-bind > .
88
9- The ` user ` object was modified. Now instead of two functions ` loginOk/loginFail ` , it has a single function ` user.login(true/false) ` .
9+ Đối tượng ` user ` đã được sửa đổi. Bây giờ thay vì hai hàm ` loginOk/loginFail ` , chỉ còn một hàm duy nhất ` user.login(true/false) ` .
1010
11- What to pass ` askPassword ` in the code below, so that it calls ` user.login(true) ` as ` ok ` and ` user.login(false) ` as ` fail ` ?
11+ Phải truyền gì vào ` askPassword ` trong đoạn mã dưới đây ?
1212
1313``` js
1414function askPassword (ok , fail ) {
@@ -18,10 +18,10 @@ function askPassword(ok, fail) {
1818}
1919
2020let user = {
21- name: ' John ' ,
21+ name: ' Hùng ' ,
2222
2323 login (result ) {
24- alert ( this .name + (result ? ' logged in ' : ' failed to log in ' ) );
24+ alert ( this .name + (result ? ' đã đăng nhập ' : ' đăng nhập thất bại ' ) );
2525 }
2626};
2727
@@ -30,5 +30,5 @@ askPassword(?, ?); // ?
3030*/ ! *
3131` ` `
3232
33- Your changes should only modify the highlighted fragment .
33+ Bạn chỉ nên thay đổi dòng cuối cùng (được tô sáng) .
3434
You can’t perform that action at this time.
0 commit comments