Skip to content

Instantly share code, notes, and snippets.

Created January 21, 2014 22:38
Show Gist options
  • Save sebinsua/8549923 to your computer and use it in GitHub Desktop.
Save sebinsua/8549923 to your computer and use it in GitHub Desktop.
Solution to scoping problem
// I cannot change this object.
var normalResponseObject = {
send: function (status, data) {
alert("This was executed.");
var generateProxiedResponseSender = function (res) {
var oldSend = res.send;
var context = this;
res.send = function () {
// Problem 2: I want to be able to move the code which generates an object
// which wraps normalResponceObject elsewhere, but yet still
// have it set a reaction and status which can be accessed by another function.
context.status = arguments[0];
context.reaction = arguments[1];, context.status, context.reaction);
var handleFinalOutputsToScreen = function () {
alert("did you run this?");
var aScope = function () {
var context = {};, normalResponseObject);
setTimeout(handleFinalOutputsToScreen.bind(context), 500);
var anotherScope = function () {
// Assume that this was being called later on against the normalResponseObject but not here.
normalResponseObject.send(200, {
hey: 5
Copy link

This is my original solution to this problem:

It may not be beautiful, but it is at least becoming more explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment