override method javascript code example

Example 1: override function javascript class

class newArray extends Array{
    push(value) {
        //execute any logic require before pushing value onto array
        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' is what methodOverride will look for
method override in your UPDATE route: 
* <form action = "/campgrounds/<%=campground._id%>/edit?_method=PUT" 
	method = "POST">
and EDIT routes:

Tags:

Java Example