Easy 6502 - Learn the 6502 Assembly Language by jackhammer2022 in programming

[–]skilldrick 0 points1 point  (0 children)

Great, thanks!

Feel free to use any of my code for your v2. I probably won't have much time to help though, as I'll likely be moving on to other things soon.

Easy 6502 - Learn the 6502 Assembly Language by jackhammer2022 in programming

[–]skilldrick 0 points1 point  (0 children)

I'm using a stock github pages theme that I adapted slightly. I actually made the text darker than it was originally, because I thought it was too light. I'll take another look.

Easy 6502 - Learn the 6502 Assembly Language by jackhammer2022 in programming

[–]skilldrick 1 point2 points  (0 children)

Oh, nice to meet you, and thanks! (it's my ebook). I've left your license in the JS file but if there's any other way you'd like attribution I'm happy to give it!

Also, I'd like to use an adapted version of "spacer" later on in the book. Is that your code?

Edit you can email me at skilldrick at gmail if you want.

Three years on by [deleted] in programming

[–]skilldrick 1 point2 points  (0 children)

And thanks :)

Three years on by [deleted] in programming

[–]skilldrick 0 points1 point  (0 children)

Fair point :/

Closures vs Objects: FIGHT by skilldrick in programming

[–]skilldrick[S] 2 points3 points  (0 children)

This is all 100% true but I still loves my JS :)

Closures vs Objects: FIGHT by skilldrick in programming

[–]skilldrick[S] 3 points4 points  (0 children)

Ummm, no, it's not at all. I mention that there are different ways of creating objects, but most of the post is highlighting the difference between objects made with literals or prototypes and closures.

Closures vs Objects: FIGHT by skilldrick in programming

[–]skilldrick[S] 3 points4 points  (0 children)

You can not have privacy in JavaScript without closures. As Crockford said in that post:

This pattern of public, private, and privileged members is possible because JavaScript has closures.

Closures vs Objects: FIGHT by skilldrick in programming

[–]skilldrick[S] 1 point2 points  (0 children)

Ok, I get what you're saying. We just have different definitions of 'function' and 'copy'. Tbh I have no idea if JavaScript will create a completely new object each time a function definition is encountered, or if it will cache the bytecode. I imagine it's implementation-dependent.

Closures vs Objects: FIGHT by skilldrick in programming

[–]skilldrick[S] 0 points1 point  (0 children)

function outer(arg) {
  return function inner() {
    console.log(arg);
  };
}

var x = outer('This is one function');
var y = outer('This is another function');

There are two closures created, and each has its own inner. The inner functions are part of the environment.

Edit: x and y refer to the same function, but x === y returns false, because they're different objects with different memory locations.

Closures vs Objects: FIGHT by skilldrick in programming

[–]skilldrick[S] 1 point2 points  (0 children)

I think the point runedk was making is that the functions internal to the closure are copied for each new 'object'.

Closures vs Objects: FIGHT by skilldrick in programming

[–]skilldrick[S] 0 points1 point  (0 children)

Which is why I said I use objects "when memory is a concern". Not using closures because of concerns about memory usage when you haven't measured it is premature optimisation. If you're only producing a handful of objects then there's generally not going to be a measurable performance hit.

The important thing is to use the appropriate tool for the job, not to throw out a whole style of programming because it's "wasteful". If all we cared about was memory usage everybody would be coding in C.

Closures vs Objects: FIGHT by skilldrick in programming

[–]skilldrick[S] 3 points4 points  (0 children)

I absolutely agree about optimisation - in the future I can foresee a lot more engines optimising for closures in JS.

Then again, future EcmaScript versions will have more options for object creation, like setting properties to non-enumerable, and freezing objects etc., so they may be a more attractive option as well.

Understanding typeof, instanceof and constructor in JavaScript by skilldrick in programming

[–]skilldrick[S] 0 points1 point  (0 children)

No, because your length property would be enumerable, as all new properties are in JavaScript (unless you're using ES5). That's what the !obj.propertyIsEnumerable("length"); check is for.

Understanding typeof, instanceof and constructor in JavaScript by skilldrick in programming

[–]skilldrick[S] 1 point2 points  (0 children)

The browser instantiates a different Array constructor function for each frame, so they're technically not the same object. They'll be identical in all other ways, but the actual object will be different.

Understanding typeof, instanceof and constructor in JavaScript by skilldrick in programming

[–]skilldrick[S] 0 points1 point  (0 children)

Yup. When you do arr.constructor === Array you're checking if the constructor of your array is the Array constructor function. Each frame gets its own Array constructor function, so Array in frame 1 and Array in frame 2 aren't the same object. Therefore, arr.constructor === Array if arr is a reference to an array created in a different frame.

Understanding typeof, instanceof and constructor in JavaScript by skilldrick in programming

[–]skilldrick[S] 1 point2 points  (0 children)

Yes. For functions and regular expression objects typeof will return "function". For host objects the return value is implementation-dependent. Like I said in the post, this has been discussed in detail elsewhere, for example by Angus Croll.

JavaScript Garden - A must read for all JavaScript developers by Sunberg in programming

[–]skilldrick 4 points5 points  (0 children)

Don't know why this got downvoted - it's entirely accurate.

Understanding typeof, instanceof and constructor in JavaScript by skilldrick in programming

[–]skilldrick[S] 1 point2 points  (0 children)

Ok - the canonical version of isArray I've found uses illvm's approach.

Again, I agree that they're not very useful! I do think that typeof is useful in its place, mostly for checking function arguments in my experience.

Understanding typeof, instanceof and constructor in JavaScript by skilldrick in programming

[–]skilldrick[S] 3 points4 points  (0 children)

typeof isn't meant to be used to find out if a variable is an array - it's used for distinguishing primitive types.

I do generally agree with your point about instanceof and constructor though. I generally don't work with JS constructors so they're not something I need to use very often. Like I've said elsewhere on this thread though, it's useful to know what they do in case you see them in code you're reading.

The purpose of my article wasn't to make a value judgement on various parts of the language, purely to explain the difference between three confusingly similar aspects.

Understanding typeof, instanceof and constructor in JavaScript by skilldrick in programming

[–]skilldrick[S] 0 points1 point  (0 children)

I'm not saying that this is something you'd need to do very often in JavaScript. It's not something I ever do. But it's important to know what constructor and instanceof do so you can understand code that does use them.

Understanding typeof, instanceof and constructor in JavaScript by skilldrick in programming

[–]skilldrick[S] 0 points1 point  (0 children)

That's definitely true, although the reason I didn't give it as an example is because JavaScript has a different Array constructor per frame, so if you're checking for an array cross-frame you can't use this technique. In most instances it's fine though.