Hi i am using an api but i should make a patch for it
Songapi.prototype.goPlaySong=Songapi.prototype.goPlaySong.toString().replace('["universal","emi","warner"]) !== -1','false');
doesn't work also tried
Songapi.prototype.goPlaySong=Function(Songapi.prototype.goPlaySong.toString().replace('["universal","emi","warner"]) !== -1','false'));
or
Songapi.prototype.goPlaySong=eval(Songapi.prototype.goPlaySong.toString().replace('["universal","emi","warner"]) !== -1','false'));
still couldn't do it any idea?
asked Jul 15, 2013 at 15:27
user2061745
3052 gold badges3 silver badges12 bronze badges
-
I'm not sure you can edit functions just like that. You could maybe store their code into a string, replace, and then eval the string, and finally set it as the function.Virus721– Virus7212013年07月15日 15:29:41 +00:00Commented Jul 15, 2013 at 15:29
-
He wants to replace a test in a parsed function by an hard coded false boolean.Virus721– Virus7212013年07月15日 15:30:36 +00:00Commented Jul 15, 2013 at 15:30
-
@Virus721: Oh! Thanks. I didn't see how that was working.gen_Eric– gen_Eric2013年07月15日 15:31:37 +00:00Commented Jul 15, 2013 at 15:31
-
It seems to me you don't even understand what you are doing. You cannot just replace something therevladkras– vladkras2013年07月15日 15:33:09 +00:00Commented Jul 15, 2013 at 15:33
3 Answers 3
SongApi is a constructor a.k.a a class.
function inherits(child, parent) {
function temp() {};
temp.prototype = parent.prototype;
child.prototype = new temp();
child.prototype.constructor = child;
};
var CustomizedApi = function() {
SongApi.call(this);
};
inherits(CustomizedApi, Songapi);
// or use Object.create for inheritance.
CustomizedApi.prototype = Object.create(SongApi.prototype);
/**
* @override
*/
CustomizedApi.prototype.goPlaySong = function() {
// override with whatever you want.
};
var api = new CustomizedApi;
api.goPlaySong();
answered Jul 15, 2013 at 15:33
flavian
28.6k11 gold badges68 silver badges107 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Try :
eval('var code = ' + Songapi.prototype.goPlaySong.toString().replace('["universal","emi","warner"]) !== -1','false'));
Songapi.prototype.goPlaySong = code;
But this is absolute dirtiness.
answered Jul 15, 2013 at 15:32
Virus721
8,42314 gold badges78 silver badges130 bronze badges
Comments
var newgoPlaySong=Songapi.prototype.goPlaySong.toString().replace('$.inArray(response.provider,["universal","emi","warner"]) !== -1','false');
eval('Songapi.prototype.goPlaySong = '+gecicigoPlaySong+';');
it worked thanks
answered Jul 15, 2013 at 15:36
user2061745
3052 gold badges3 silver badges12 bronze badges
Comments
lang-js