functionDoggo(name,vegetarian){//the constructor can take in variables
this.species='doggo'
this.fluffy=true
this.talk='woooof'
this.name=name
this.vegetarian=vegetarian
//Doesn't have to return anything
}
//method:
Doggo.prototype.introduce=//Class.prototype is the object used to create the prototype of the object created (which we then refer to with Object.getPrototypeOf() or Object.setPrototypeOf())
function(){
if(this.vegetarian)
return'Hai, my name is '+this.name+' and I am a vegetarian'
else
return'Hai, my name is '+this.name+' and I am not a vegetarian'
}
clifford=newDoggo('Clifford',false)
clifford.introduce()
veggie=newDoggo('Veg',true)
veggie.introduce()
marvin={
// 1. create empty object
varmarvin={}
// 2. run constructure with object as this
Doggo.call(marvin,"Marvin",false)
// 3. sets marvin's prototype to Bunny.prototype
Object.setPrototypeOf(marvin,Doggo.prototype)
/////// DONE ////////
returnmarvin
}
marvin.introduce()
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.