Code Monkey home page Code Monkey logo

Comments (13)

pasaran avatar pasaran commented on August 10, 2024

Т.е. проверять, если в прототипе есть hasOwnProperty onhtmlinit, то сразу биндить его на соответствующее событие?

Еще один минус событий -- в отличие от методов они не наследуются (хотя мы и не часто наследование используем, все равно)

from noscript.

chestozo avatar chestozo commented on August 10, 2024

А может быть надо сделать наследование событий, нет?

from noscript.

pasaran avatar pasaran commented on August 10, 2024

Может быть.
Собссно вроде я в наноблоках такое делал.

from noscript.

chestozo avatar chestozo commented on August 10, 2024

Т.е. проверять, если в прототипе есть hasOwnProperty onhtmlinit, то сразу биндить его на соответствующее событие?

Да. С этим-то всё ок? Делаем?

from noscript.

pasaran avatar pasaran commented on August 10, 2024

Да, это думаю полезно.
Леша? /cc @doochik

from noscript.

pasaran avatar pasaran commented on August 10, 2024

По мотивам устного обсуждения.
Я хочу определять view/model'и как-то так:

var messages = {};

messages.methods = {};

messages.methods.foo = function() {
    ...
};

messages.events = {};

messages.events.onhtmlinit = function() {
    ...
};

messages.events.onFoo = 'foo';

no.define('messages', messages);

Потом я просто из корня проекта grep'ом легко нахожу, что угодно, например, messages.events.onhtmlinit.

Сравни с вариантом типа:

var events = {
    'onhtmlinit': function() {
        ...
    },
    ...
};

Плюс еще париться про запятые при комментировании/удалении/перестановке кусков кода.

Вот.
Другой вопрос -- нужен ли этот синтакс-шугер, чтобы метод onhtmlinit автоматически биндился как соответствующее событие.

from noscript.

chestozo avatar chestozo commented on August 10, 2024

Парирую тем, как сейчас мы это делаем:

var methods = {};

methods.foo = function() {
    ...
};

methods.onhtmlinit = function() {
    ...
};

no.define('messages', {
  events: {
    'foo': 'foo',
    'htmlinit': 'onhtmlinit'
  },
  methods: methods
});

from noscript.

pasaran avatar pasaran commented on August 10, 2024

Ну вот тут та же проблема -- по строчке methods.onhtmlinit непонятно, чей именно это метод.
Вот, например, все ast-классы в yate определены в одном файле: https://github.com/pasaran/yate/blob/master/lib/asts.js
И их очень легко искать.
Что в редакторе, что грепом.

from noscript.

chestozo avatar chestozo commented on August 10, 2024

Ну ты ведь видишь имя файла когда грепаешь?
Там понятно будет, что это view и завётся оно messages.

from noscript.

doochik avatar doochik commented on August 10, 2024

я почему то никогда не ищу view.prototype.onhtmlinit, а иду в определение view и смотрю туда :)

from noscript.

pasaran avatar pasaran commented on August 10, 2024

Ну когда у тебя этих файлов 5-10-15 -- более-менее. У меня в яте тоже так было поначалу.
Потому, когда их под сотню становится, понимаешь, что когда они в одном файле -- это проще и легче и быстрее.

from noscript.

chestozo avatar chestozo commented on August 10, 2024

А когда 10 больших файлов в одном? )

from noscript.

mmoo avatar mmoo commented on August 10, 2024

А чё-то действительно, можно же сразу писать function в events. Тогда, наверно, можно и не делать. Эти методы обычно больше нигде не нужны сами по себе.

from noscript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.