Trying to “extend” myStuff object with a new method in a plugin-style fashion, but when I call the new plugin’s method ($.validate.newthing()), I get a function does not exist error for it.
How can I properly extend myStuff with the “validation” plugin below?
<script type="text/javascript">
var myStuff = function(){
return {
thingy: function() {
// Stuff
}
}
}();
(function($){
$.validate = function() {
return {
newthing: function(a) {
return a + a;
}
}
}
})(myStuff);
(function($) {
console.log($.validate.newthing(2));
})(myStuff);
</script>
In your example,
validateis a function that, when called, returns an object containing thenewthingfunction. You need to replace this:With this: