JSFiddle - React, Tailwind, and code Playground

JavaScript

var Book = function(id, name, price) {
  this.id = id;
  this.name = name;
  this.price = price;
}

Book.prototype.display = function() {
alert('id=' + this.id + 'name=' + this.name + 'price=' + this.price);
} 

//Book.prototype = {
//	show:function(){
//  	alert(this.price);
//  }
//};

// 在类的原型上添加属性和方法,有两种方式,一是为原型对象属性赋值,另一种是将一个对象赋值给类的原型对象。但是两种方式不要混用。


var b = new Book(1, 2, 3);
alert(b.id);
b.display();
//b.show();