搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
JavaScript 教程
JavaScript 函数
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>JavaScript 函数call()示例 - 基础教程(div.cn)</title> <body> <p>要访问Web浏览器的控制台,请先按键盘上的F12键以打开开发人员工具,然后单击控制台选项卡。</p> <script> function Product(name, price) { this.name = name; this.price = price; } function Food(name, price) { Product.call(this, name, price); this.category = "food"; } function Toy(name, price) { Product.call(this, name, price); this.category = "toy"; } let cheese = new Food("cheese", 12); let robot = new Toy("robot", 85); console.log(cheese); console.log(robot); </script> </body> </html>
运行结果