override method javascript code example
Example 1: override function javascript class
class newArray extends Array{
push(value) {
console.log(`pushed ${value} on to array`)
super.push(value)
}
}
var array = new newArray
array.push('new Value')
Example 2: method override
using method-override in your index.js
1. npm install method-override --save
2. var methodOverride = require("method-override");
3. app.use(methodOverride("_method"));
method override in your UPDATE route:
* <form action = "/campgrounds/<%=campground._id%>/edit?_method=PUT"
method = "POST">
and EDIT routes: