HJ90,
var Some = function () {};
Some.prototype.method1 = function () {
console.log(1);
return this;
};
Some.prototype.method2 = function () {
console.log(2);
return this;
};
Some.prototype.method3 = function () {
console.log(3);
return this;
};
var some = new Some();
some.method1().method2().method3().method1().method2().method3();//...
|
tsigel, спасибо за ответ!
Но вот Some('') или some('') отдельно как функцию мы уже не можем использовать. Только вместе с методами. Как же в jquery это сделано... $('#el') $('#el').method('') Ведь $ это обычная функция а всякие css, attr - объекты внутри этой функции |
HJ90,
var $ = function (some) {
if (!(this instanceof $)) {
return new $(some);
}
console.log(some);
};
$.prototype.method1 = function () {
console.log(1);
return this;
};
$.prototype.method2 = function () {
console.log(2);
return this;
};
$.prototype.method3 = function () {
console.log(3);
return this;
};
$('test').method1().method2().method3().method1().method2().method3();//...
$('test').method1();
var t = $('test');
t.method2();
|
tsigel, о! ..То что я хотел.
2 дня потратил и без толку. Но меня уже затянуло разобраться в этом. Спасибо большое за пример! |
| Часовой пояс GMT +3, время: 19:35. |