This question seems hard to form so I will just provide an example of what I am trying to accomplish::
function test(word) {
return word
}
function replaceWord(word) {
return word
}
test('Hello').replaceWord('World')
So I want to be able to return "Hello" and if I want to, chain the replaceWord function.
Comparable to how jquery handles things like
$('#element').something('doit').somethingElse();
I feel like I am on the right track with
var test = function (word) {
return word;
}
test.prototype = {
replaceWord: function (word) {
return word;
}
}
But since I am returning the string, the chain will not work. What is the proper way I am supposed to doing this to be be able to have a function that can return a value [test('Hello')] and also can act as an object to modify data for value/s returned by the function [test('Hello').replaceWord('World')] leaving the value at 'World'?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…