Object literal object builder error javascript

综合技术 2018-05-18

I am trying to organize my code using the object literal pattern, but I am getting an error: Uncaught ReferenceError: backToTop is not defined

Any ideas why?

Here's the code:

(function($){

  var Mk = {

    config: {},

    init: function(config) {
      backToTop();
      wow();
      progressBarAnimation();
      slabText();
    },

    backToTop: function() {
      $('body').append('
Back to Top
'); $(window).scroll(function () { if ($(this).scrollTop() != 0) { $('#toTop').fadeIn(); } else { $('#toTop').fadeOut(); } }); $('#toTop').click(function(){ $("html, body").animate({ scrollTop: 0 }, 600); return false; }); }, wow: function() { var wow = new WOW({ boxClass: 'wow', animateClass: 'animated', offset: 0, mobile: true, live: true }); wow.init(); }, progressBarAnimation: function() { $.each($('div.progress-bar'),function(){ $(this).css('width', $(this).attr('aria-valuetransitiongoal')+'%'); }); }, slabText:function() { $("h1.mklife").slabText({ "viewportBreakpoint":400 }); }, last:'' }; $(document).ready(Mk.init()); window.Mk = Mk; })(jQuery)
  • Edit: I had missed the actual function call parentheses on document ready: $(document).ready(Mk.init());

The functions backToTop
, wow
, progressBarAnimation
, slabText
are methods of the Mk object, to access them reference the Mk object

init: function(config) {
  Mk.backToTop();
  Mk.wow();
  Mk.progressBarAnimation();
  Mk.slabText();
},

or since init is also a method of the same object you can access the function with the this
keyword

init: function(config) {
  this.backToTop();
  this.wow();
  this.progressBarAnimation();
  this.slabText();
},
Hello, buddy!

责编内容by:Hello, buddy! (源链)。感谢您的支持!

您可能感兴趣的

Comment.js:一个纯JS实现的静态站点评论系统... 前言 我的博客最早是使用 Disqus 来实现评论功能的。Disqus 被墙了之后,改成了多说。今年年初,多说也正式关闭了,于是我被逼着又开始寻找其他的替代评论系统。 我先是试用了网易云跟贴、...
js 如何获取手机软键盘高度 ?「输入框被弹起的软键盘给遮挡了?」之 IOING 原理解析... 前言 当我提出这个问题的时候很多同学的脑袋都在快速回忆 js 是否存在这么一个 API ?如果有那这篇文章就到此结束吧。 对于这样一个具有普遍性的问题浏览器偏偏没有给出解决方案,what?没有...
CSS Ease-in-out to full screen I have a black background div of a size which contains an image.#Banner { positio...
Move the background image diagonally across the sc... I'm new here, so I can't comment/follow-up yet on another question that PARTIALLY provided an answer...
Define the header of the response content type in ... I have a use case where I make a cross domain JSONP request. $.ajax({ url: "http://anyorigin....