cach 1 - 1
RUN
<script> function User() { // Thuộc tính this.username = ''; this.password = ''; // Phải return this thì mới tạo mới được đối tượng return this; } // Bổ sung phương thức User.prototype.setInfo = function(username, password){ this.username = username; this.password = password; }; User.prototype.checkLogin = function(){ return (this.username === 'admin' && this.password === '@123'); }; // Cách sử dụng var user = new User(); user.setInfo('admin', '@123'); if (user.checkLogin()){ alert('Đăng nhập thành công'); } else{ alert('Đăng nhập thất bại'); } </script>
PHÓNG TO