Constructors ============ ```Example from 1 languages: JavaScript class Person { constructor(name) { this._name = name } } new Person("Jane") ``` ```Example from 1 languages: C++ class Foobar { public: Foobar(double r = 1.0, double alpha = 0.0) // Constructor, parameters with default values. : x_(r * cos(alpha)) // <- Initializer list { y_ = r * sin(alpha); // <- Normal assignment } private: double x_; double y_; }; Foobar a, b(3), c(5, M_PI/4); ``` ```Example from 1 languages: C# public class MyClass { private int a; private string b; // Constructor public MyClass() : this(42, "string") { } // Overloading a constructor public MyClass(int a, string b) { this.a = a; this.b = b; } } // Code somewhere // Instantiating an object with the constructor above MyClass c = new MyClass(42, "string"); ``` ```Example from 1 languages: Chapel proc init ``` ```Example from 1 languages: Toit constructor x: ``` ```Example from 1 languages: CFML component { // properties property name="cheeseName"; // constructor function Cheese init( required string cheeseName ) { variables.cheeseName = arguments.cheeseName; return this; } } ``` ```Example from 1 languages: Speedie class Foobar |float| x |float| y constructor (|float| r=1, |float| alpha=0) .x = r * alpha.cos .y = r * alpha.sin || a = foobar() || b = foobar(3) || c = foobar(5, M_PI/4) ``` * Languages *with* Constructors include JavaScript, Python, Java, C++, PHP, C#, MATLAB, Objective-C, Chapel, Visual Basic .NET, Toit, Dale, Object Pascal, CFML, Action!, Aardvark, Speedie * Languages *without* Constructors include C, C3, C2, progsbase * View all concepts with or missing a *hasConstructors* measurement http://pldb.info/../lists/explorer.html#columns=rank~id~appeared~tags~creators~hasConstructors&searchBuilder=%7B%22criteria%22%3A%5B%7B%22condition%22%3A%22null%22%2C%22data%22%3A%22hasConstructors%22%2C%22origData%22%3A%22hasConstructors%22%2C%22type%22%3A%22num%22%2C%22value%22%3A%5B%5D%7D%5D%2C%22logic%22%3A%22AND%22%7D missing http://pldb.info/../lists/explorer.html#columns=rank~id~appeared~tags~creators~hasConstructors&searchBuilder=%7B%22criteria%22%3A%5B%7B%22condition%22%3A%22!null%22%2C%22data%22%3A%22hasConstructors%22%2C%22origData%22%3A%22hasConstructors%22%2C%22type%22%3A%22num%22%2C%22value%22%3A%5B%5D%7D%5D%2C%22logic%22%3A%22AND%22%7D with * Read more about Constructors on the web: 1. https://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) 1. Built with Scroll v178.2.3