<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script type="text/javascript"> class Person{} let p=new Person(); //增加 p.name="cyg"; //p["name"]="liwen"; p.say=function() { console.log("cyg"); } /*p["say"]=function() { console.log("liwen1"); }*/ console.log(p); </script> </body> </html>
删除:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script type="text/javascript"> class Person{} let p = new Person(); p["name"] = "zs"; p["say"] = function(){ console.log("hello world"); } //删除 delete p["say"]; console.log(p); </script> </body>
修改;
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script type="text/javascript"> class Person{} let p = new Person(); p["name"] = "zs"; p["say"] = function(){ console.log("hello world"); } //修改: p["name"]="liwen"; p["say"]=function() { console.log("liwen1"); } console.log(p); </script> </body> </html>
查询:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script type="text/javascript"> class Person{} let p = new Person(); p["name"] = "zs"; p["say"] = function(){ console.log("hello world"); } //查询 console.log(p["name"]); console.log(p["say"]); </script> </body> </html>