我是javascript新手.对不起,如果我的问题有问题.
如何将方法或插件注入/创建/扩展到我们自己的库?这是"yourlib.js"
var Yourlib = (function() {
// privt. var
var selectedEl = {}
// some privt. funct
function something() {
}
return {
getById : function() {
},
setColor : function() {
}
}
}());
Run Code Online (Sandbox Code Playgroud)
以下是你的"plugin.js"
/*
How to create the plugin pattern?
Example: I want to create/inject a method/plugin named "setHeight" .
So, i can call it later, like this: Yourlib.getById('an-id').setHeight(value);
How is the pattern?
*/
Run Code Online (Sandbox Code Playgroud)