Chapters
33 Chapters
|
3:02:08
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.2.0
Subscribe to download the code!Compatible PHP versions: ^7.2.0
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
17.
Extending the Prototype
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial uses an older version of Symfony... but since it's a JavaScript tutorial, the concepts are still ? valid!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.2.0",
"symfony/symfony": "3.1.*", // v3.1.10
"twig/twig": "2.10.*", // v2.10.0
"doctrine/orm": "^2.5", // v2.7.1
"doctrine/doctrine-bundle": "^1.6", // 1.10.3
"doctrine/doctrine-cache-bundle": "^1.2", // 1.3.2
"symfony/swiftmailer-bundle": "^2.3", // v2.4.0
"symfony/monolog-bundle": "^2.8", // 2.12.0
"symfony/polyfill-apcu": "^1.0", // v1.2.0
"sensio/distribution-bundle": "^5.0", // v5.0.22
"sensio/framework-extra-bundle": "^3.0.2", // v3.0.16
"incenteev/composer-parameter-handler": "^2.0", // v2.1.2
"friendsofsymfony/user-bundle": "~2.0@dev", // dev-master
"doctrine/doctrine-fixtures-bundle": "~2.3", // v2.4.1
"doctrine/doctrine-migrations-bundle": "^1.2", // v1.2.1
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"friendsofsymfony/jsrouting-bundle": "^1.6" // 1.6.0
},
"require-dev": {
"sensio/generator-bundle": "^3.0", // v3.1.1
"symfony/phpunit-bridge": "^3.0" // v3.1.6
}
}
8 Comments
As touched upon at the end of the video, if you want to instantiate RepLogApp for multiple tables, assuming they've got the same class, you can do so as follows:
I ran into something weird when calling new RepLogApp($wrapper). In my constructor in RepLogApp.js I instantiate the object like window.RepLogApp = function($wrapper) {}; When I instantiate the new RepLogApp($wrapper) object, there is an error in the console: jquery-3.1.1.min.js:2 jQuery.Deferred exception: RepLogApp is not a constructor TypeError: RepLogApp is not a constructor
Which is weird because the RepLogApp() object is setup as a constructor. When I instantiate it as var RepLogApp = new window.RepLogApp($wrapper); The constructor is initiated properly. Is there some detail I'm missing here?
Just noticed when I call the RepLogApp() constructer outside $(document).ready(); it is initialized without problems:
Hey sdewijs!
Hmm, that IS weird! So basically, when inside of $(document).ready(),
new RepLogApp($wrapper)does not work, butnew window.RepLogApp($wrapper)does work, is that correct?Unless you (somehow) have a local (non global) variable in scope called RepLogApp, RepLogApp and window.RepLogApp should be identical. You could try
console.log()each of these to see what each is. The fact that it works outside of the $(document).ready() is another mystery (but probably related): putting code inside this block basically just means its execution is delayed slightly. But, it should not change whether or not some global variable is available.You could also try copying our version of RepLogApp.js completely (you can get it from the script/code blocks on this page) to see if there is some small bug in your version. I can't think of what would cause this - especially because the self-executing block should prevent any weird variables from "leaking" out. But, as you said, this is a weird situation!
Cheers!
Yes! Changing the variable name inside document.ready does make a difference.And now it's clear what I did wrong. I wrote var RepLogApp = new RepLogApp($wrapper); with a capital R and in the course code it is var repLogApp = new RepLogApp($wrapper); The devil is in the details as always :)
Nice catch! Really, we don't even need the
repLogAppvariable - so maybe we should have just donenew RepLogApp($wrapper)with no assignment. Glad you figured it out :).Cheers!
For the $.extend is this jquery method? In JavaScript there is also _.extend also do the same thing?
Hey Jian,
Yes, jQuery has extend() method, see the docs: https://api.jquery.com/jque... . So $.extend() calls this jQuery method if $ is an object of jQuery of course. JavaScript also has similar method, but it's called extends() (note the "s" at the end) - here's the docs: https://developer.mozilla.o... . But this JS methods is a part of ECMAScript 2015 only.
Cheers!
"Houston: no signs of life"
Start the conversation!