Вопрос

I have created a page that use jquery ui tabs and each tab load a page via ajax request.I have cached result of ajax request.My problem is inner javascript in my pages that loaded in tabs.For example I have linkClick function in both pages, when I am opening these pages linkClick function override with second method. How I can separate these method in my project.

Sincerely you Mahmood Bagheri

Это было полезно?

Решение

Use a namespace and a closure for your code/application.

Something like this:

(function (global) {

    var MYAPP = {};

    MYAPP.linkClick = function () ....

    global.MYAPP = MYAPP;

})(this);

Then whenever you need linkClick, you use MYAPP.linkClick and it does not get mixed with other names.

This way you avoid name collisions.

Другие советы

It is very bad way to define functions in such way. Make functions less specific and add parameters, this functions preferably should be located in one file which should be loaded with other libs.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top