JS Projects and Databases

class Model {
constructor(){
...
}
...
}
class Product extends Model{}
class ItemRequirement extends Model{}
class Model {
...
async post(){}
async save(){}
async destroy(){}
static async retrieve(){}
...
}
Model.retrieve()
Product.retrieve()
async post(include){
//Sends a POST request to the server
const c = this.constructor const url = c.root + c.resource const options = { method: 'POST', headers: {...c.headers}, body: JSON.stringify(packageBody(this, include)) } const response = await fetch(url, options) const obj = await fromJson(response) c.buildRelationships(obj) return c.addInstance(obj.data)}
class Product extends Model{  static resource = "products/"  static instances = []}
class Item extends Model{ static resource = "items/" static instances = []}class ItemCodeParameter extends Model { static resource = "item_code_parameters/" static instances = []}

In conclusion

Part of the fun of Javascript is how dynamic it truly is. And while this blog post only showed a small part of that, I’ve been able to enjoy the flexibility that JS really brings in bringing out dynamic and interesting web content. Going forward I’ll be introduced to React and other libraries and frameworks. I’m excited to flush out this beautiful language.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store