要将JavaScript函数用作对象,可以尝试运行以下代码-
<html>
<head>
<title>User-defined objects</title>
<script>
function book(title, author){
this.title = title;
this.author = author;
}
</script>
</head>
<body>
<script>
var myBook = new book("Amit", "Python");
document.write("Book title is : " + myBook.title + "<br>");
document.write("Book author is : " + myBook.author + "<br>");
</script>
</body>
</html>