Here is a regular constructor function:
var Hello = function (name) {
this.name = name;
};When used with new, you get what you would expect:
| // Package unshortener takes a single parameter (url) and sends back an unshortened version. | |
| // | |
| // This version is in vanilla go, and requires no packages to be installed. | |
| package main | |
| import ( | |
| "encoding/json" | |
| "io" | |
| "log" | |
| "net/http" |
| var async = require('async'); | |
| // ASYNC SWITCH patches the async module with a switch like construct for asynchronous functions. | |
| // Use like: | |
| // async.switch(sitchedVar, { | |
| // 'case 1': function (callback) {/*...*/}, | |
| // 'case 2': function (callback) {/*...*/}, | |
| // 'default': function (callback) {/*...*/} | |
| // }, callback); |
Here is a regular constructor function:
var Hello = function (name) {
this.name = name;
};When used with new, you get what you would expect:
| /* This script operates asynchronously. It can be written synchronously, but | |
| * not a lot is saved once you try-catch everything. Uses the async module. | |
| * | |
| * MIT licence. | |
| */ | |
| var fs = require('fs'); | |
| var path = require('path'); | |
| var async = require('async'); | |
| // Write as many of these as you like. |
| var dt = (function () { | |
| var start = Date.now(); | |
| return function () { | |
| return Date.now() - start; | |
| }; | |
| })(); | |
| // Some time later... |
| import 'dart:io' show HttpRequest, HttpClient, HttpServer, ContentType; | |
| import 'dart:convert' show JSON; | |
| void handleRequest(HttpRequest request) { | |
| // For convenience. | |
| var response = request.response; | |
| // No path is expected. Return with 404 for anything else. | |
| if (request.uri.path != '' && request.uri.path != '/') { | |
| response.statusCode = 404; |
| var config = require('minimist')(process.argv.slice(2)); | |
| module.exports = config; | |
| var errors = []; | |
| if (!config.hasOwnProperty('twitter-consumer-key')) { | |
| errors.push('No twitter-consumer-key given.'); | |
| } |
I hereby claim:
To claim this, I am signing this object:
| // Methods will be bound. This allows them to be public or private | |
| // later on without needing `this`. These can be required in etc. | |
| function addToCounterMixin(context, num) { | |
| context.counter += num; | |
| } | |
| // Use this to proxy a field on from one object to another. | |
| function proxy(context, obj, fieldName) { | |
| Object.defineProperty(obj, fieldName, { | |
| set: function (val) { |
| var a = true; | |
| var test = () => console.log(this.a); | |
| test(); // true | |
| var test2 = test.bind({ a: false }); | |
| test2(); // Canary: false, Firefox: true |