Essayer de "prolonger" myStuff objet avec une nouvelle méthode dans un style de plugin, mais quand j'appelle la méthode du nouveau plugin ($ .validate.newthing()), j'obtiens une fonction n'existe pas d'erreur pour cela.Comment étendre un objet avec une nouvelle méthode, "plugin-style"?
Comment puis-je étendre correctement myStuff avec le plugin "validation" ci-dessous?
<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>