A brief look at the Objects in JavaScript
2024-08-29 19:08:02
Objects
An object is a self-contained collection of data. This data comes in to forms: properties and methods
- A property is a variable belonging to an object
- A method is a function that the object can invoke
In JavaScript you can create your own objects , called user-defined objects.
JavaScript also coms with a range of premade objects that you can use in your scipts. These are called
native objects .
You may have been seen objects in action. Array is an object.
Whenever you initialize an array using the new keyword, you are creating a new instance of the
objects.when you want to find out how many elements are in an array, you do so by using the length property.
eg : var beatles = new Array();
beatles.length;
Other native objects examples include Math and Date, both of which have very useful methods for dealing
with numbers and datas respectively.
For example :
var num = 7.561;
var num = Math.round(num) ;
The Date object can be used to store and retrive infomation about a specific date and time.
If you create a new instance of the Date object, it will be automatically be prefilled with the current date
and time : eg :
var current_date = new Date();
var today = current_date.getDay();
Host objects
Native objects arent the only kind of premade objects that you can use in your scripts.
Another kind of objects supplied not by the JavaScript language itself, but by the environment in
which its running. In the case of Web, the environment is the web browser.
Objects that are supplied by the web browser are called host objects.
Host objects include Form, Image, and Element. These objects can be used to get information
about forms, images, and form elements within a web pages.
So lets take a summary of the objects in JavaScript, There are three kinds of objects in JavaScript :
- User-defined objects created from scratch by the programmer.
- Native objects like Array, Math and Date, which are built in to JavaScript
- Host objects that are provided by the browser
最新文章
- [Android Pro] android控件ListView顶部或者底部也显示分割线
- JQuery DOM clone(true),对于克隆对象事件触发后,处理函数中this指代克隆对象
- mac 下如何切换jdk的版本
- schtasks在win7下提示错误:无法加载列资源
- Qt之QRoundProgressBar(圆形进度条)
- nginx path_info问题解决
- Win7下VS2010使用STLPort 和boost1.56.
- xhr的send方法以及node如何处理get和post数据
- 项目构建之maven篇:3.m2eclipse使用
- openSUSE 安装
- iOS数据持久化之数据库:SQLite和FMDB
- TCP协议简介
- Android微信登录、分享、支付
- Zuul(SpringCloud学习笔记一)
- 30分钟,让你彻底明白Promise原理
- mysql5.7 root用户默认密码
- 六、框架<;iframe>;、背景、实体
- 使用sshfs挂载远程服务器目录
- JavaScriptConverter
- MyBatis数据库连接的基本使用