当前位置: 代码迷 >> 综合 >> es6对象的扩展底层实现____Object.values
  详细解决方案

es6对象的扩展底层实现____Object.values

热度:19   发布时间:2023-10-10 20:36:47.0
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>

 

  相关解决方案