当前位置:网站首页>JS learning notes 09-12: prototype objects, foreach+tostring and recycle bin
JS learning notes 09-12: prototype objects, foreach+tostring and recycle bin
2022-07-19 08:30:00 【The man fished alone in the cold river snow】
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script> // // Define functions in global scope , Contaminates the namespace of the global scope And it's not safe // function Person(name,age,gender){
// this.name=name;
// this.age=age;
// this.gender=gender;
// }
// // Add... To the prototype sayName Method // Person.prototype.sayName=function(){
// alert("Hello Hello everyone , I am a :"+this.name," Age is :"+this.age," The gender is :"+this.gender);
// };
// // Create a Person Example
// var per=new Person(" The Monkey King ",18," male ")
// var per1=new Person(" Pig eight quit ",18," male ")
// per.sayName();
// per1.sayName();
// Create a constructor function MyClass() {
}
// towards MyClass Add a name attribute
MyClass.prototype.name = " I'm the name in the prototype ";
var mc = new MyClass();
mc.age=18;
console.log(mc.name);
// You can use the hasOwnProperty() To check whether the object itself contains the property
// When we use an object's properties or methods , Will now find in itself ,Object The prototype of the object is useless , If in Object Still not found in , Then return to undefined
console.log(mc.hasOwnProperty("age"));
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
// Create an array
var arr=[" The Monkey King "," Pig eight quit "," The sand monk "," Tang's monk "," Bones jing "];
/* forEach() Method requires a function as an argument We create but not call , We call it a callback function Passed in as an argument , We can define formal parameters , The browser will pass three parameters in the callback function first : The element being traversed , the second , Currently traversing the index of the element , Third The array being traversed */
arr.forEach(function(value,index,obj){
console.log(value,index,obj);
});
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script> function Person(name, age, gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
// Create a Person example
var per = new Person(" The Monkey King ", 19, " male ");
// When we print an object directly on the page , Event is the output of the object toString() Return value of method
// If we want to output objects without output [object object], You can add a toString() Method
var result = per.toString();
// Whether in prototype object
console.log(per.__proto__.__proto__.hasOwnProperty("toString"))
// Garbage collection (GC)
// We need a garbage collection mechanism , To deal with the garbage generated in the process of program running
// When an object has no variables or attributes to reference it , At this point we will never be able to manipulate the object , Too many objects take up a lot of space , Cause memory operation delay
//- stay JS There is an automatic garbage collection mechanism , There is no need to recycle
var obj=new Object();
// Do various operations on objects ... Set unused objects to null that will do
obj=null;
</script>
</head>
<body>
</body>
</html>
边栏推荐
- US pressure surges, tiktok changes global safety director
- 超干货!彻底搞懂Golang内存管理和垃圾回收
- Consul服务注册与发现
- 凭借左程云(左神)的这份 “程序员代码面试指南”我入职了字节
- Super dry! Thoroughly understand golang memory management and garbage collection
- unity 自定义天空球模型防止被裁剪
- 5.2 数据库安全
- Bean、
- Textview text up and down
- Redis常用数据类型——Redis列表(List)和Redis 集合(Set)
猜你喜欢

Redis overview installation

Real case: how to check the soaring usage of CPU after the system goes online?

Talk about distributed locks

Deep learning 7 deep feedforward network

Redis6 new data type - hyperloglog

ES6学习-函数(严格模式,高阶函数,闭包)

Unity: window size adaptation when running on the browser after webgl Publishing
![[kernel] character device that drives development and learning](/img/99/2eaed37078c3245be29d82382cfd59.png)
[kernel] character device that drives development and learning

SCA在得物DevSecOps平台上应用

Redis新数据类型——Bitmaps
随机推荐
巴西移动游戏代投出海机遇与挑战
力扣43字符串相乘笔记
Wvppro-zlm-gb21818-camera
1. Flask Foundation
Redis6 新数据类型——Geospatial
Application of SCA on devsecops platform
Consul服务注册与发现
把HBuilderX的主题变成vscode
[kernel] character device that drives development and learning
美国压力激增,TikTok 更换全球安全主管
Redis common data types - hash and ordered set Zset (sorted set)
JS学习笔记06-08:数组的遍历以及数组的四个方法
65、Restful规范
Obtain the home location through IP
畅玩JVM——关于GC垃圾回收必须要掌握的知识
總結的太好了!終於有人把SQL的各種連接Join都講明白了
Redis介绍
New redis6 features
Microservices and microservice architecture
visual studio 2022(VS 2022)无法读取内存的问题