0

My task was to create an object/class called MrFreeze and mark this object as frozen so that no other changes can be made to it.] I came up with the following solution which worked:

Object.freeze(MrFreeze);

But then as I viewed the solutions provided on http://www.codewars.com I came across this code:

(Object.freeze || object)(MrFreeze);

I fail to understand this line of code. Please explain why this works when using a OR object operator.

3
  • please Explain this javascript function? Commented Jan 17, 2014 at 13:11
  • this is my working code and i understand it Object.freeze(MrFreeze),BUT I need explanation on this line of code: (Object.freeze || object) (MrFreeze) Commented Jan 17, 2014 at 13:14
  • You need to add some supporting code to help people understand the context and therefore be able to help you. Commented Jan 17, 2014 at 13:16

1 Answer 1

1

Seems like a fallback to me.

when Object.freeze does exist it performs:

Object.freeze(MrFreeze);

when Object.freeze doesn't exist it performs:

object(MrFreeze);

This might as well be written as (more verbose for clearification):

function freeze(MrFreeze, object) {
    if (Object.freeze) {
        Object.freeze(MrFreeze);
    }
    else {
        object(MrFreeze);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.