2020 10 22 Day 25 ReactJs Functions, Sum Problem, React Parse Register User

Опубликовано: 03 Июль 2026
на канале: Web Development
143
0

Day 25 (22nd October, 2020).
1. Oo Js Function, rewrite themselves.
2. Problems Anagram Method 2
3. React Login, Register and Logout.

Function, Rewrite Thyself.
Because a function can return a function, you can use new function to replace the old one.
function a() {
alert('I am A');
return function() {
alert('i am B');
}
}
a = a();
a();
We have function a(), to overwrite the actual a() function:
a = a();

Here, it will alert I am A initially, and next time when we call a(), it will show I am B.
This is useful when a function has some initial one-off work to do.
The function overwrites itself after the first call in order to avoid doing unnecessary repetitive work.
Redefine the global variable a, assigning a new function to it.
Every subsequent time that the function is call, it will alert I am B.

var a = (function() {
function setup() {
alert('setup is done');
}
function actualWork() {
alert('work is going on');
}
setup();
return actualWork;
})();
a();

These techniques could be really useful when working in the browser envirnonment. Because different browsers can have different ways of achieving same thing and you know that the browser features don't change between function calls, you can have a function determine the best way to do the work in the current browser.

React Register Steps:
Steps:
A. Register Page
3 fields, name, email, password,
Submit Button

Gather name, email, password in some variable so that I can take that and pass it to backend.

On clicking the submit button, form is submitted, we use above variables for name, email, password and we send it to backend.

Show message to user or we redirect user to home page.

We should show the error to user if any.