Show
Built - in Object là gì?Built - in Object là các đối tượng được xây nhà cung cấp xây dựng sẵn (hay còn gọi là được tích hợp sẵn). Chúng ta chỉ cần lấy ra và sử dụng. Ngoài console, còn có các đối tượng (object) khác được tích hợp sẵn vào JavaScript. Sau này bạn sẽ biết cách xây dựng đối tượng của riêng bạn , nhưng bây giờ những đối tượng có sẵn này có đầy đủ các chức năng hữu ích. Built-in Object - Đối tượng được tích hợp sẵn trong Javascript Điều tuyệt vời về các đối tượng là chúng có các phương thức (method) có sẵn theo nó! Hãy gọi phương thức .random() từ đối tượng Math được tích hợp sẵn: Thử nghiệm với đối tượng Math được JS tích hợp sẵnTrong ví dụ trên, chúng ta đã gọi phương thức .random() bằng cách nối thêm tên đối tượng với tên của phương thức (medthod) bằng toán tử dấu chấm (dot operator), và mở và đóng dấu ngoặc đơn. Phương thức này trả về một số ngẫu nhiên giữa 0 và 1. Để tạo một số ngẫu nhiên từ 0 đến 50, chúng tôi có thể nhân kết quả này với 50, như sau: Ví dụ, ở trên có thể sẽ kết quả nhận được sẽ là số thập phân. Để đảm bảo kết quả là một số nguyên, chúng ta có thể tận dụng một phương thức hữu ích khác của Math gọi là Math.floor(). Trường hợp này máy tính sẽ làm như sau:
Để xem tất cả các thuộc tính và phương thức của đối tượng Math, hãy xem tài liệu chuẩn ở đây Bài tập thực hành sử dụng đối tượng được tích hợp sẵn.Để hiểu hơn về Object trong Javascript, hãy thử làm các bài tập sau. Sử dụng tài liệu chuẩn để tìm kiếm phương thức có sẵn của đối tượng Math để:
Đăng ký tư vấn Nhân viên gọi điện tư vấn miễn phí sau khi đăng ký Được cập nhật các ưu đãi sớm nhất Hotline: 0383180086
Hãy đăng ký để nhận những thông tin mới nhất về học bổng mới nhất tại NIIT - ICT Hà Nội This chapter documents all of JavaScript's standard, built-in objects, including their methods and properties. The term "global objects" (or standard built-in objects) here is not to be confused with the global object. Here, "global objects" refer to objects in the global scope. The global object itself can be accessed using the
Other objects in the global scope are either created by the user script or
provided by the host application. The host objects available in browser contexts are documented in the API reference. For more information about the distinction between the DOM and core JavaScript, see
JavaScript technologies overview. These global properties return a simple value. They have no properties or methods. Function propertiesThese global functions—functions which are called globally, rather than on an object—directly return their results to the caller.
Fundamental objectsThese are the fundamental, basic objects upon which all other objects are based. This includes general objects, booleans, functions, and symbols.
Error objectsError objects are a special type of fundamental object. They include the basic
Numbers and datesThese are the base objects representing numbers, dates, and mathematical calculations.
Text processingThese objects represent strings and support manipulating them.
Indexed collectionsThese objects represent collections of data which are ordered by an index value. This includes (typed) arrays and array-like constructs.
Keyed collectionsThese objects represent collections which use keys. The iterable
collections (
Structured dataThese objects represent and interact with structured data buffers and data coded using JavaScript Object Notation (JSON).
Control abstraction objectsControl abstractions can help to structure code, especially async code (without using deeply nested callbacks, for example).
ReflectionInternationalizationWebAssembly |