Skip to content

Instantly share code, notes, and snippets.

@cihad
Created August 7, 2018 20:32
Show Gist options
  • Save cihad/3f7cda7f704c0f38ac2baf49ffdc1a40 to your computer and use it in GitHub Desktop.
Save cihad/3f7cda7f704c0f38ac2baf49ffdc1a40 to your computer and use it in GitHub Desktop.
local variable overriding
// Almak istedigimiz degisken 'a'
function Vehicle(){
}
Vehicle.prototype.go = function(){
var a = "deneme"
}
// Fonksiyondaki kod calismadan yukle
function getVariable() {
$buDegiskeneAl = null;
goFunc = Vehicle.prototype.go;
oldCode = goFunc.toString();
oldCodePart1 = oldCode.slice(0,oldCode.length-1);
oldCodePart2 = "}";
codeToInsert = "$buDegiskeneAl = a";
var newCode = oldCodePart1 + codeToInsert + oldCodePart2;
var newFunc = eval("newCode")
eval ("Vehicle.prototype.go= " + newFunc);
}
getVariable();
// 'a' nin bulundugu fonksiyon calissin
var v = new Vehicle();
v.go()
console.log($buDegiskeneAl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment