JSFiddle - React, Tailwind, and code Playground

by alirokni

HTML

var myObject = { firstName:"John", lastName: "Doe", fullName: function () { return this.firstName + " " + this.lastName; } } myObject.fullName();

http://stackoverflow.com/questions/4859800/should-i-be-using-object-literals-or-constructor-functions
http://stackoverflow.com/a/30097697

JavaScript

var myObj = {
  z: 12,
  decrement: function() {
    this.z--;
  }
}
var dec = myObj.decrement(); // assign function to dec after execution
dec; // is undefined 
console.log("one is " + myObj.z);
myObj.decrement();
console.log("second is " + myObj.z);



function Car(brand, model, color, engin) {
  var b = brand,
    m = model,
    c = color,
    e = engin;
  var show = function() {
    console.log(b + " " + m + " " + c + " " + e);
  };
  show();
}
var bmw = new Car('bmw', 'sedan', 'metalic', '325i');

var nCar = {
  b: 'brand',
  m: 'model',
  c: 'color',
  e: 'engin',
  show: function() {
    console.log(this + " \n " + this.b + " " + this.m + " " + this.c + " " + this.e);
  }
};
nCar.show();