Môn JS
Môn JS
.children[i]
.removeChild
remove() là xóa phần tử con nên nếu phần tử cần xóa không phải con thì sẽ lỗi
document.getElementById("tbody/pt
cha").removeChild(document.getElementById(pt con));
parentNode
childNodes[nodenumber]
firstChild
lastChild
nextSibling
previousSibling
sort date
const latestMovies = moviesWithReleaseDate
.sort((a, b) => {
return moment(a.release_date).diff(b.release_date);
})
.reverse()
.slice(0, 20);
Hàm sự kiện
REACT:
*{()=>tenHam()} //tenHam(e)
*={tenHam()}
Vòng lặp
*oj trong oj => dùng thuộc tính của oj bao ngoài => dùng for in
VD:
newArr.push({
id: key,
title: data[key].title,
date: data[key].date
});
//trả về danh sách các film được sắp xếp theo trường popularity giảm dần
};
sortedMovieList,
20,
req.params.page ? req.params.page : 1
);
_
return res.status(200).json({
results: movieList20ItemsPerPage,
})
{props.years
.sort((a, b) => b - a)
.map((year) => (
{year}
</option>
))}
</select>
onChange
*get e.target
onChange={()=>selectYear()}
=> onChange={selectYear}
Ngày tháng
*Lấy tháng, dạng chữ, tiếng Anh thì "en-US", nếu để "default" thường là tiếng Việt
*Date Picker
https://www.npmjs.com/package/react-date-range
<DateRange
editableDateInputs={true}
moveRangeOnFirstSelection={false}
className="date"
minDate={new Date()}
onChange={...}
ranges={...}
/>
class
as we code complex programs, we'll need to create many similar but distinct
objects. For example, all the books in the library.
But creating a new object for thousands of books would take a lot of time and
could lead to errors.
To make this process less error-prone and more efficient, we can use data
structures called classes as templates. Once we create a template with the
properties we'll want for all similar objects, we can use it to create new objects
faster.
To create new objects, classes need a special method called the constructor().
This method sets the property values for a new object.
Every time we create an oj from a class, we're creating what's called an instance
of that class.
constructor(author, title){
this.author: author;
this.title: title
read(){}
book1.read();
because instances are independent, they let us keep track of complicated date
like a huge number of users on a website. In this example, we keep track of four
users and whether they're online. A real website might keep track of hundreds.
class User{
constructor(name){
this.name = name;
this.isOnline = true;
this.preiods = 4;
the constructor() can be empty. Contructors are so essential for classes that a
default constructor is created even if we don't add it.
Imagine we're making a zoo game. The animals in the zpp have a lot in common,
but they're also different in many ways. That's where inheritance comes into play.
Vd: class Dog extends Animal {} => inheritance gives a class all the properties and
methods of the class it's extending or inhering from. Here, Dog is a subclass of the
Animal class. The Animal class, then, is its superclass.
constructor(name){
this.name = name;
console.log(dog.name);
lấy phương thức từ class có chọn lọc và thêm thắt mới, thì dùng super
attack(){
tương tự khi muốn chép properties => dùng super() trong constructor {}
promise
promises are objects that represent the outcome of an asynchronous operation. It
can be fulfilled or rejected. When we're waiting to know the result, the promise is
pending. To create a new Promise oj, we use the new keyword and the Promise
constructor method. The constructor takes a function as a parameter. The
passed-in function itself taskes two parameters. The first is resolve and the
second is reject.
The promise constructor passes its own resolve and reject functions into the
constructor. If the promise if fulfilled, the resolve function changes the promise
status from pending to fulfilled. The resolve function takes one argument.
return new
Promise(function(resolve, reject){
console.log(makeOrder);
Once a promise is resolved, we need to handle the resolved or rejected data. =>
we use .then to include actions for when the promise is no longer in the pending
state.
makeOrder.then(function(successValue){console.log
what if the promise is not fulfilled? The .then method won't execute and we'll get
an uncaught error. To sort this out, we can use the .catch method to handle
errors when the promise is rejected
vd: .catch(function(failureValue)
Await waits for the promise to be resolved. Await pauses the execution of async
code inside the asyncFunction until createNewPromiseFunction is resolved
touch event
.addEvenListener("touchstart",) chạm
.addEvenListener("touchmove",) lướt
.addEvenListener("touchcancel",) khi bị gián đoạn => gọi hàm liên quan đến error
oninput
const input = document.querySelector('input');
const log = document.getElementById('log');
function undateValue() {
input.oninput = updateValue;
get attribute
by a .
by using .getAttribute("src")
querySelector
collections are similar to arrays. They work with indices that start from 0
innerHTML
tableBodyEl.innerHTML = ""
textContent: Hello
function
đặt tên: động từ, vd sumTotal (các hàm tương tự nhau thì động từ phía trước
cũng nên giống nhau), hoặc isFreezing (với giá trị boolean)
JSON
We can create jsonVariable like a regular oj {} but wrapped with single quotes '