Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 5. Использование пакетов
- В самом языке нет поддержки пакетов. Увы. Так что придется использовать какую-нибудь библиотеку.
- Пример такой библиотеки:
- function namespace(){};
- /**
- * create new namespace if it is not exist
- * @param newNamespace string namespaces like "aaa.dddd.fff"
- */
- namespace.prototype.useNamespace = function(newNamespace){
- var namespaces = newNamespace.split(".");
- if (!this[namespaces[0]]){
- this[namespaces[0]] = new namespace();
- }
- if (namespaces.length > 1){
- this[namespaces[0]].useNamespace(newNamespace.substring(namespaces[0].length+1));
- }
- };
- Далее в приложении создаем корневой пакет…
- var app = new namespace();
- … и переводим на него наши классы:
- app.useNamespace("model.note");
- app.model.note.NoteDocument = function(str){
- ...
- }
- ...
- var doc = new app.model.note.NoteDocument("hello!");
- doc.init();
Advertisement
Add Comment
Please, Sign In to add comment