Skip to content

Instantly share code, notes, and snippets.

@alex28742
Last active January 6, 2017 09:50
Show Gist options
  • Save alex28742/00085f6480eee7a123c3aa1e15c0cc4c to your computer and use it in GitHub Desktop.
Save alex28742/00085f6480eee7a123c3aa1e15c0cc4c to your computer and use it in GitHub Desktop.
jQuery libs and OOP study
============================================================================
создание своей библиотеки
// my lib
var base_param = (function() {
var module = {}
// в параметрах переменные
module.init = function(first, second) {
// инициализация входящими параметрами;
module.one = first || "first";
module.two = second || "second";
return module;
}
// вызов функции - метода
module.my_func = function(params) {
alert('my_func is work!');
return module;
}
// в параметрах объект
module.init2 = function(params) {
module.a = params.one;
module.b = params.two;
return module;
}
return module; // возвращаю наполненный функциями
}())
// на входе переменные
base_param.init('aaa', 'bbb');
// на входе объект
base_param.init2({ one: 'первый', two: 'второй' });
============================================================================
Использование "объекта" (использовал в курсе по node js)
// подключение "языкового файла json" в node js
var phrases = require('./ru');
// инициализация псевдо-класса
function User(name) {
this.name = name;
}
// добавление метода
User.prototype.hello = function(who) {
console.log(phrases.Hello + ", " + who.name);
}
// создание объекта класса
var vasya = new User("Вася");
// использование метода объекта
vasya.hello(petya);
-----------------------------------------
содержимое файла ru.json для фраз
{
"Hello": "Привет"
}
// использование в файле (выше)
var phrases = require('./ru');
....phrases.Hello...
============================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment