Skip to content

Instantly share code, notes, and snippets.

View Rhino "_private" naming convention.js
/* by Dmitry A. Soshnikov */
var object = (function () {
// private
var _x = 10;
// also private
function _privateFunc() {
return _x;
View evaluation strategy.cpp
/* by Dmitry A. Soshnikov */
#include "stdafx.h"
#include <iostream>
struct Object {
int x;
int y;
};
View object-proto-aliases.js
/**
* Aliases and additional "sugar"
* 2010-04-15
* @author Dmitry A. Soshnikov
*/
(function () {
var
$break = {},
hasOwn = Object.prototype.hasOwnProperty;
View reference-is-a-sugar-for-a-pointer.txt
C++ source:
void call_by_reference(int& x)
{
x = 20;
}
void call_by_pointer(int* x)
{
*x = 20;
View Object.essence.js
/**
* by Dmitry A. Soshnikov
*/
Object.defineProperty(Object, "essence", {
value: function objectEssence(value) {
var essence = {kind: Object.prototype.toString.call(value).slice(8, -1)};
// use Object(value) just for shortness, it's less effective
// than typeof value == "object" && value !== null || typeof value == "function"
essence[value === Object(value) ? "object" : "primitive"] = true;
View AO-parameters-arguments.js
/**
* Abstract representation of ES3
* or ES5-non-strict sharing of
* passed formal parameters and
* corresponding indexes of the
* arguments object
*
* Implemented in ES5, non-strict
* tested in BESEN rev. 109
*
View mixin.js
/**
* Delegation based mixins for JavaScript.
*
* Non-specific extensions are used:
* __proto__
* __noSuchMethod__
*
* Tested in SpiderMonkey.
*
* Opened issues:
View firefox-arguments-bug.js
// Latest Firefox (including nightly):
// INCORRECT with FDs
(function () {
// a function declaration
// does not replace arguments object
function arguments() {}
alert(arguments); // "[object Object]", should be function
View while-loop-code-gen.cpp
// loop-code-gen.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
int i = 0, n = 1;
View while-loop-code-gen-gcc.c
int main()
{
int i = 0, n = 1;
while (i++ < n) if (i == 1) break;
while (i++ < n && i != 1);
return 0;
}