Skip to main content

Posts

Showing posts with the label object

How to get json data from a file (jQuery)

Just cant figure it out. I have a large object stored as a JSON file and I want to access it once and use it multiple times: var myjson = new Object(); $.getJSON("myJSON.js", function(json) { myjson = JSON.stringify(json); }); $('#console').append(myjson); This does nothing. It's a scope issue, I know. I just don't know how to do what I'm wanting. Must I do all my functions inside the $.getJSON call or is there a way to pass the object that I can use throughout runtime?

JavaScript "this" confusion

This is probably pretty easy, yet I am confused, so maybe I might still learn something more today. I am trying to do the following: var myObj = {}; myObj.src = {} myObj.src.A = ['1.png','2.png','3.png']; myObj.A = new Image(); myObj.A.src = this.src.A[0]; This will result in an Uncaught TypeError: Cannot read property 'A' of undefined error. When I use myObj.src.A[0] instead of this it is working fine. What would be the correct way to use this in this context?

Does using method chaining in PHP cause any problems with resources or memory?

I'm talking about methods like this: $object->method()->method1('param')->method2('param'); Those are created by returning the object in the function. return $this; I've seen third-party software use that method, but I'm wondering, wouldn't that cause a bit of a problem with the resources or memory because you're continuously returning the entire object?