0

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?

4
  • 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. Commented Jul 15, 2013 at 15:29
  • He wants to replace a test in a parsed function by an hard coded false boolean. Commented Jul 15, 2013 at 15:30
  • @Virus721: Oh! Thanks. I didn't see how that was working. Commented Jul 15, 2013 at 15:31
  • It seems to me you don't even understand what you are doing. You cannot just replace something there Commented Jul 15, 2013 at 15:33

3 Answers 3

3

DEMO

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();
Sign up to request clarification or add additional context in comments.

Comments

1

Try :

eval('var code = ' + Songapi.prototype.goPlaySong.toString().replace('["universal","emi","warner"]) !== -1','false'));

Songapi.prototype.goPlaySong = code;

But this is absolute dirtiness.

Comments

0
var newgoPlaySong=Songapi.prototype.goPlaySong.toString().replace('$.inArray(response.provider,["universal","emi","warner"]) !== -1','false');
eval('Songapi.prototype.goPlaySong = '+gecicigoPlaySong+';');

it worked thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.