Object.values的用法:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Object.values</title>
</head>
<body>
</body>
<script>
class Student{
constructor(name, age) {
this.name=name;
this.age=age;
}
}
var stu = new Student("小刚",18);
var keys=Object.values(stu);
console.log(keys.toString());
</script>
</html>
Object.values的底层实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
<script>
class Student{
constructor(name, age) {
this.name=name;
this.age=age;
}
}
Student.prototype.Objectvalues = function () {
var buffer = [];
for(key in this) {
buffer.push(this[key]);
}
return buffer;
}
var stu = new Student("小刚",18);
let keys = stu.Objectvalues();
console.log(keys.toString());
</script>
</html>