[javascript] What techniques can be used to define a class in JavaScript, and what are their trade-offs?

_x000D_
_x000D_
//new way using this and new_x000D_
function Persons(name) {_x000D_
  this.name = name;_x000D_
  this.greeting = function() {_x000D_
    alert('Hi! I\'m ' + this.name + '.');_x000D_
  };_x000D_
}_x000D_
_x000D_
var gee=new Persons("gee");_x000D_
gee.greeting();_x000D_
_x000D_
var gray=new Persons("gray");_x000D_
gray.greeting();_x000D_
_x000D_
//old way_x000D_
function createPerson(name){_x000D_
 var obj={};_x000D_
 obj.name=name;_x000D_
 obj.greeting = function(){_x000D_
 console.log("hello I am"+obj.name);_x000D_
 }; _x000D_
  return obj;_x000D_
}_x000D_
_x000D_
var gita=createPerson('Gita');_x000D_
gita.greeting();
_x000D_
_x000D_
_x000D_

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to oop

How to implement a simple scenario the OO way When to use 'raise NotImplementedError'? PHP: cannot declare class because the name is already in use Python class input argument Call an overridden method from super class in typescript Typescript: How to extend two classes? What's the difference between abstraction and encapsulation? An object reference is required to access a non-static member Java Multiple Inheritance Why not inherit from List<T>?

Examples related to class

String method cannot be found in a main class method Class constructor type in typescript? ReactJS - Call One Component Method From Another Component How do I declare a model class in my Angular 2 component using TypeScript? When to use Interface and Model in TypeScript / Angular Swift Error: Editor placeholder in source file Declaring static constants in ES6 classes? Creating a static class with no instances In R, dealing with Error: ggplot2 doesn't know how to deal with data of class numeric Static vs class functions/variables in Swift classes?