Created
August 7, 2018 20:32
-
-
Save cihad/3f7cda7f704c0f38ac2baf49ffdc1a40 to your computer and use it in GitHub Desktop.
local variable overriding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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